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 |
JR83
Starting Member
31 Posts |
Posted - 2014-08-07 : 08:34:25
|
I want to incorporate a Check constraint within a trigger, based on this but im struggling with the coding.Assuming that is an Alphanumeric field you should be checking what value is in the alphanumeric column from inserted, comparing it with whatever is in the AMGR_User_Fields_Tbl to see if there’s a duplicate and then raising the errorThis is my Trigger:ALTER TRIGGER [dbo].[DUPLICATES]ON [dbo].[AMGR_User_Fields_Tbl]FOR INSERT, UPDATEASDECLARE @Alphanumericcol VARCHAR (750)-- This trigger has been created to check that duplicate rows are not inserted into table.-- Check if row existsSELECT @AlphanumericcolFROM Inserted i, AMGR_User_Fields_Tbl tWHERE t.AlphaNumericCol = i.AlphaNumericColAND t.Client_Id = i.Client_Id-- (@Alphanumericcol = 1)-- Display Error and then Rollback transactionBEGINRAISERROR ('This row already exists in the table', 16, 1)ROLLBACK TRANSACTIONEND |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-08-07 : 10:01:23
|
Duplicate of [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=195602[/url] |
 |
|
|
|
|