Click here to Skip to main content
15,034,131 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have emp2 table, i wanted to apply before insert trigger on salary column and i need another table with old values.
i was trying to execute this code it troughs as an error..help me to solve this problem..

What I have tried:

create trigger sal_tr
before update of salary
on emp2
begin
insert into emp_bkp(:old.ename,old.salary);
end;
Posted
Updated 15-May-17 20:28pm

--> First of all, SQL Server uses Transact SQL[^] not PL/SQL[^]. PL/SQL is used by ORACLE, IBM DB2 etc.
--> SQL Server doesn't have BEFORE INSERT trigger, it has INSTEAD OF INSERT[^] trigger for similar (but not same) purpose.
--> Triggers are defined on TABLE/VIEW not on column
--> Surprisingly, your code doesn't contain a BEFORE INSERT trigger, rather it has BEFORE UPDATE trigger. They are different.

If you are looking for INSTEAD OF UPDATE trigger in SQL Server check following-
INSTEAD OF UPDATE Triggers[^]
SQL Server: Instead Of Update Trigger Example[^]
After Trigger, Instead of Trigger Example[^]

If your requirement is something different, please let me know.

Hope, it helps :)
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900