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)
 trigger insert

Author  Topic 

cristuballa
Starting Member

13 Posts

Posted - 2003-10-02 : 02:46:58
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

i got this code from NR which, updates the value of a field(fld1) from table tb2 whenever record is inserted into tab1. and i'm a bit confuse.

What does i.fld2, t, i means?






Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-10-02 : 07:05:52
These are table aliases. Look up "Using Table Aliases" in Books Online.

Jay White
{0}
Go to Top of Page

james_yoder@hotmail.com
Starting Member

9 Posts

Posted - 2003-10-02 : 09:52:25
This statement is using aliases.

Here is how it works...
the line
from tbl2 t - is saying tbl2 can be referenced as t
join inserted i - is saying the inserted table (inserted) can be referenced as i

Stands to reason, then that i.fld2 really is referncing the fld2 column in the inserted table.

FYI an inserted table is an automatically generated temp table that contains the new row that is being inserted into your table. This will go away after the insertion is completed.

Hope this helps clear things up.

James
Go to Top of Page
   

- Advertisement -