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 |
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-02-13 : 17:02:55
|
hi there , i want something like a trigger to raise an error "you cannot update this record" if you are trying to update a record where the column "city" = miami for examplethats waht i need, a trigger to raise an error if you are trying to update my table customers if the column city=miamithanks in advancedi apreciate your help |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-13 : 18:18:36
|
write an instead of trigger for that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-02-14 : 07:08:19
|
hi visakh16thanks for always answer my threads,could you give me an extra hand i dont know too much about triggersany example with my case or similar onethanks in advanced |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-14 : 09:51:45
|
quote: Originally posted by sebastian11c hi visakh16thanks for always answer my threads,could you give me an extra hand i dont know too much about triggersany example with my case or similar onethanks in advanced
in your case it will be likeCREATE TRIGGER YourTriggerNameON yourTableINSTEAD OF UPDATEASBEGIN UPDATE tSET t.col1=i.col1,t.col2=i.col2FROM INSERTED iINNER JOIN Yourtable tON t.PK = i.PKAND t.city <> 'Miami'IF EXISTS (SELECT 1 FROM INSERTED i INNER JOIN YourTable t ON t. t.PK = i.PK AND t.city = 'Miami' )RAISERROR ('You cant update Miami based details',16,1)END INSERTED is internal temporary table used by triggerPK is primary key of yourtablecol1,col2 etc are other columns in yourtable------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sebastian11c
Posting Yak Master
129 Posts |
Posted - 2012-02-14 : 10:19:25
|
awesome, thanks a lot ..one more time thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-14 : 10:22:06
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|