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.
| Author |
Topic |
|
wormz666
Posting Yak Master
110 Posts |
Posted - 2008-10-05 : 21:48:44
|
| i have a problem with the trigger.....i dont want duplicate in my table.....declare @lname varchardeclare @fname varcharif Exists(Select lname,fname from sample1 where lname=@lname and fname=@fname) begin raiserror 14000 'Existing Record' rollback transaction endplease help....thank you in advance |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-06 : 00:05:35
|
two approaches.1.Easiest way is to set unique constraint on column where you want to avoid duplicate values2.Another way is to use an INSTEAD OF TRIGGERCREATE TRIGGER YourTrigger ON sample1INSTEAD OF INSERTASIF NOT EXISTS(Select lname,fname from sample1 where lname=@lname and fname=@fname)INSERT INTO sample1SELECT fields FROM INSERTED |
 |
|
|
|
|
|