Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Insert Trigger

I want to write a trigger to avoid appending duplicate records in a table. How can I know the new value of the columns inside the trigger? (SQL 2000)

CREATE TRIGGER [trg_append] ON [dbo].[tbl_ec_master_findings]
FOR INSERT
AS
if (select count(*)
from tbl_ec_master_findings
where tbl_ec_master_findings.str_facility =@str_facility) <> 0
begin
print "already exists."
rollback transaction
end
[456 byte] By [rkbnair] at [2007-11-11 8:29:40]
# 1 Re: Insert Trigger
Within a trigger, there's a virtual table named 'inserted' whose columns contain the values being inserted into the database. See http://www.sqlteam.com/item.asp?ItemID=3850 for more information.
Phil Weber at 2007-11-11 23:47:09 >
# 2 Re: Insert Trigger
Phil,

It works.

You are so helpful to me.

Thanks so much.
rkbnair at 2007-11-11 23:48:04 >