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 2000 Forums
 Transact-SQL (2000)
 help in create trigger

Author  Topic 

farnooshhp
Starting Member

1 Post

Posted - 2009-03-18 : 03:15:46
hello
i am new in triggers!! i have a table1 with a count field and i want to increase it when table2 will be inserted.
how can i write trigger for this purpose?
is this correct?

create trigger addcont
on table2
after insert
as
update table1 set count = count+1
where id = table2id

and two tables are connected with id field

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-18 : 03:54:02
[code]create trigger addcont
on table2
after insert
as


update t1
set [count] = [count]+1
from table1 as t1
inner join inserted as i on i.id = t1.id [/code]


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

- Advertisement -