Trigger based on Insert/Update/Delete | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Trigger based on Insert/Update/Delete

I’m pretty new to triggers, but have a requirement to update a 2nd table based on Insert, Update and Delete to one main table. So when PS_DEPT_TBL has either update, insert or delete action, I need it to update PS_IWAY_CTL table. The columns on PS_IWAY_CTL table include: TABLENAME (IE.PS_DEPT_TBL)
PRIMARY_KEY_1
ACTION (INSERT, UPDATE, DELETE)
DATE (CURRENT DATE AND TIME)
The Primary key on PS_DEPT_TBL is SETID. To begin: CREATE TRIGGER PS_DEPT_TBL_TRG
ON HR83ZAP.PS_DEPT_TBL
AFTER INSERT, UPDATE, DELETE
AS appreciate input

Hi,
Read about create trigger in BOL.Basic idea is that You create a trigger and you get access to virtual tables which stores the rows inserted or rows deleted from prevoius operation into physical table. So in your trigger access rows from such tables and then you can insert those rows or delete those rows into any table you wish
Read about inserted, deleted virtual tables and also read about cascade delete and insert throughly in BOL which might interests you.

i have same requirement as "networkassist",
so, if someone fulfill this requirement here with trigger code , i’ll very thankful to him. appreciate input
I’m pretty new to sqlserver triggers, but have a requirement to update a 2nd table based on Insert, Update and Delete to one main table. So when PS_DEPT_TBL has either update, insert or delete action, I need it to update PS_IWAY_CTL table. The columns on PS_IWAY_CTL table include: TABLENAME (IE.PS_DEPT_TBL)
PRIMARY_KEY_1
ACTION (INSERT, UPDATE, DELETE)
DATE (CURRENT DATE AND TIME)
The Primary key on PS_DEPT_TBL is SETID. To begin: CREATE TRIGGER PS_DEPT_TBL_TRG
ON HR83ZAP.PS_DEPT_TBL
AFTER INSERT, UPDATE, DELETE
AS please, give me trigger code for this requirement appreciate input
Welcome to the forum!
Check out this Books Online topic: Using the inserted and deleted Tables
]]>

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |