all groups > sql server programming > april 2005 >
You're in the

sql server programming

group:

original value in an update trigger


RE: original value in an update trigger CBretana
4/28/2005 7:08:04 PM
sql server programming: Yes, SQL server creates 2 temporary tables named "Inserted" and "Deleted"
when an Update query runs. The deleted table contains all the records as
they were before the update, and the inserted tab;e contains the records with
the values as they will be after they are updated.

The Inserted table is created for Inserts and Update Queries, and the
Deleted table is created for Delete and Update queries...

[quoted text, click to view]
original value in an update trigger Nir Frumer
4/28/2005 8:51:15 PM
hi
Is there a way to determine

the original value and the current value of a field within an update
trigger?



thanks in advance,

Nir.

RE: original value in an update trigger ZULFIQAR SYED
4/28/2005 9:10:09 PM
To echo CBretana explanation, here is an example for you.

HTH, Thanks

set nocount on
go

create table t(col int)
go

insert t values(1)
insert t values(2)
insert t values(3)
insert t values(4)
go

select * from t
go

create trigger tt on t
for update
as
declare @i int
select @i=col from inserted
print 'new value'
print @i

select @i=col from deleted
print 'old value'
print @i

go


update t set col=44 where col=4
go

select * from t
go

drop trigger tt
drop table t
go



--
http://zulfiqar.typepad.com
MCP


[quoted text, click to view]
AddThis Social Bookmark Button