Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi there. I'm a SQL DBA that has unfortunately never been exposed to writing triggers, etc. Now I'm stuck and don't know how to go about it.I need to write after triggers for six different tables. These triggers need to fire when data in certain columns are updated, inserted or deleted. When the trigger fires it writes certain columsn from Table A to another table, Table B with the first column of Table B being a combiation of the table name + the local timestamp converted to character format. They sent me a version they took from Oracle and changed somewhat, but I cannot make heads or tails from this. Where can I get example codes for triggers? Please, I need urgent help with this.Regards,DStuff the people, I am the people!
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2008-09-16 : 03:14:45
something like
CREATE TRIGGER YourTriggerName ON YourTableAFTER INSERT,UPDATE,DELETEASINSERT INTO TableBSELECT 'YourTable' + CONVERT(varchar(11),GETDATE()),d.fields,i.fieldsFROm INSERTED iFULL OUTER JOIN DELETED dON d.PK=i.PK