Minnu (12/17/2013)
Hi,Thank you for Speedy response.
my question is, when i print the values from trigger
print @id
print @name
Print '--'
am getting
1
D
--
but as per my table id's 1 and 2 are updting, i want 1 and 2 values to be print as output.
Please suggest.
triggers in SQL have to assume they are touching more than one row of data; as soon as you assign a value(ie SELECT @id = ID FROM INSERTED) you break that rule; if there are multiple rows in the insert/update, you end up getting the first or last row of the data assigned to the variable...and you don't know which one it was.
so for a spot check during development, yeah maybe i'd see a variable, but it should not exist once your testing is complete.
in general, if i see a variable in a trigger, i assume it's written incorrectly.
this is one of the first spot checks i run when reviewing a new-to-me database
--triggers have variables defined?
select * from sys.triggers where object_definition(object_id) like '%@%'
if this command was inserted, which values, woudl you think appear in your print statments? there are four values to choose from for each column:
INSERT INTO Test([ID],[Name],[Desc])
SELECT '1','D','Desk' UNION ALL
SELECT '2','D','Desk1' UNION ALL
SELECT '3','X','TBT1' UNION ALL
SELECT '4','Y','TXT'
Lowell