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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Triggers

Author  Topic 

darkangelBDF
Starting Member

1 Post

Posted - 2008-09-16 : 03:10:02
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,
D

Stuff 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 YourTable
AFTER INSERT,UPDATE,DELETE
AS
INSERT INTO TableB
SELECT 'YourTable' + CONVERT(varchar(11),GETDATE()),d.fields,i.fields
FROm INSERTED i
FULL OUTER JOIN DELETED d
ON d.PK=i.PK



PK is primary key of yourtable
Go to Top of Page
   

- Advertisement -