September 25, 2005 at 8:31 am
How to Create Trigger on the Table and coulumn
i've a tebles called Emp & EmpHis
whenever updating Emp Table, sal Column, Immidiatly Insert or Update that Employee in EmpHis Table
Please Help
With Best Regards
Arif
September 25, 2005 at 11:27 am
CREATE TRIGGER TR_EMPLOYER_HISTORY /*NAME OF TRIGGER*/
ON dbo.[Emp Table] /*NAME OF TABLE
/*Darn spaces*/
FOR UPDATE /*ONLY FOR UPDATES*/
/*Only inserts when the salary is modified*/
INSERT INTO EmpHis
( /*COLUMNNAMES HERE*/
)
SELECT
INSERTED.Column1,INSERTED.Column2,...
FROM INSERTED /*CONTAINS THE MODIFIED DATA*/
INNER JOIN DELETED /*CONTAINS THE ORIGINAL DATA*/
ON INSERTED.IDColumn=DELETED.IDColumn /*matching employer*/
WHERE ISNULL(INSERTED.sal,-1) <> ISNULL(DELETED.sal,-1)
/*Only salary changes*/
See the books on line for more info on triggers.
Greetings, Jo
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply