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
 General SQL Server Forums
 New to SQL Server Programming
 insert n update trigger

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-04-15 : 03:26:27
how can i create a trigger which checks when i m inserting one value in one table T1 ,and this ttigger updates this same value in table T2

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-04-15 : 03:43:41
[code]CREATE TRIGGER dbo.trgTable1
ON dbo.Table1
AFTER INSERT,
UPDATE
AS

UPDATE t2
SET t2.Col9 = i.Col9
FROM dbo.Table2 AS t2
INNER JOIN inserted AS i ON i.pkCol = t2.pkCol[/code]


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-05-05 : 03:09:37
can i have trigger on two tables simultaneously
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-05 : 05:14:44
Yes, you can have practically as many triggers as you want.
You can even hav multiple triggers on same table, and you have even have multiple triggers of same type on same table.
However, there are no guarantees triggers will be fired in same order for every execution.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-05 : 07:30:30
quote:
Originally posted by qutesanju

can i have trigger on two tables simultaneously


do you mean same trigger created for two tables? if yes, no not possible. you need separate trigger for each table. trigger is always created on a table for particular event(s). You can however refer other table inside that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-05-05 : 08:01:13
Not entirely true.
You have database triggers with SQL Server 2008, for which you can capture sql statements and act accordingly.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -