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 |
|
sinva
Starting Member
23 Posts |
Posted - 2010-04-08 : 10:18:10
|
| I have never written a trigger before and now am seeing the light. Isthere a way to write a trigger so that if a user changes on a column A ina single row on table A then the trigger could check if other table B has a column X equals to table A column B and table B column Y has a value equals to "A" will raise an error. Thanks,Create table A(A varchar(10),B varchar(10))Create table B(X varchar(10),Y varchar(10)) |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-04-08 : 10:28:19
|
| Yes, you can write a trigger, but please keep in mind that trigger is not fired for single row but for entire scope of statement. For example, if your update statement updates 10 rows, trigger will be fired only once for all the 10 rows.Harsh Athalyehttp://www.letsgeek.net/ |
 |
|
|
sinva
Starting Member
23 Posts |
Posted - 2010-04-08 : 10:30:57
|
| Would you mind please post some exmaple here? As I do not have any idea about it now. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-08 : 11:01:56
|
something likeCREATE TRIGGER YourtriggerON YourTableAFTER INSERT,UPDATEAS BEGINIF EXISTS (SELECT 1 FROM INSERTED i JOIN TableB b ON b.X=i.B AND b.Y = i.A)RAISERROR ('Your Error Message', 16,1 )END------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|