How to wite Tiggers in sql?
Give me the example......
How to wite Tiggers in sql?
Give me the example......
Lets say you want to create trigger on table1 having columns id and name.
The syntax would be
create trigger insert on my_table as
begin
insert into my_table values (0,"new NAME inserted")
end
for any insert into your my_table object as below:
insert into my_table values (1,"name1")
O/P will be:
id name
-- ------
1 name1
0 new NAME inserted
The above is an example for insert trigger.
Similarly you can create update and delete triggers.
Last edited by keerthv; 04-23-2008 at 05:58 AM.
By SQL if you mean SQL Server then please find a related discussion here.
Hi usha, here is an example.. Example to create table level or statement triggers create or replace trigger secure_emp before insert on emp begin if to_char(sysdate,’dy’) in(‘sat’,’sun’) or to_char(sysdate,’hh24:mi’) not between ’08:00’ and ’18:00’ then raise_application_error(-20001,’you may insert into emp table only during business hours..’); end if; end; / here is the output.. testing secure_emp insert into emp (empno, ename) values (101,’ravi’); error at line 1 ora-20001 you may insert into emp table only during business hours ora-06512 at plsql secure_emp, line 4 ora-04088 error during execution of trigger “plsql secure_emp” regards, e.sagar.
Please mention the server name.
DML triggers syntax
create or replace triggerBefore/After insert/update/delete on
inserting .....
or
updating.....
or
deleting .....
end
Instead of trigger syntax
create or replace trigger < trigger name> Instead of insert/update/delete on
end
DDL trigger syntax
create or replace triggerlogon on