June 7, 2005 at 1:11 pm
Hi,
I have a trigger which runs on every insert and update of the table. I want to assign some value to the column in that table only if the record is getting inserted.
In oracle I can check it by the following statement
if (inserting) then
do soming
end if
Is there anything in SQL SERVER to check if the trigger is inserting or updating the table?
Kavita
June 7, 2005 at 1:14 pm
if not exists (Select * from Deleted) and Exists (Select * from Inserted)
begin
Update...
end
June 8, 2005 at 7:46 am
or just set a DEFAULT for that column.
If it's being updated, it would be already there, and the default wouldn't do anything... if it's inserted, it would populate that column with a value.
Unless you want a different value based on another column in the inserted row? Not sure of defaults can handle this... I don't think so.
June 8, 2005 at 7:48 am
No, that would take a computed column or a trigger .
June 8, 2005 at 7:51 am
Thanks
I have used " if not exists (Select * from Deleted) and Exists (Select * from Inserted)" and now trigger is running like a champ.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply