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
 SQL Server Development (2000)
 sql trigger

Author  Topic 

cristuballa
Starting Member

13 Posts

Posted - 2003-09-21 : 23:23:08
i'm just new to sql trigger, and i have no idea on how to add/minus a numeric field value on a certain table whenever i insert record on other table. can show me how or refer me to existing tutorials.

thanx in advance


nr
SQLTeam MVY

12543 Posts

Posted - 2003-09-22 : 00:02:56
See
http://www.nigelrivett.net/Triggers_1_A_beginners_guide.html

Something like
create trigger tr_mytbl_ins on tbl1 for insert
as

update tbl2
set fld1 = fld1 + i.fld2
from tbl2 t
join inserted i
on tbl2.FK = i.PK
go


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

cristuballa
Starting Member

13 Posts

Posted - 2003-09-22 : 03:28:33
thanx NR
Go to Top of Page

cristuballa
Starting Member

13 Posts

Posted - 2003-09-22 : 03:41:34
does inserted function captures the latest inserted record?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-09-22 : 07:37:07
inserted is not a function, it is a (pseudo) table that contains ALL of the rows affected by the last INSERT or UPDATE operation.
Go to Top of Page
   

- Advertisement -