There should be no transaction conflict, the trigger is part of the same transaction.
Could you show us please the trigger code you use?
Main Topics
Browse All TopicsDear expert:
I have a table that has a lot of fields, say fields A, B, C, .... I want to add a trigger that, if there is an update which is updating field B, it put also the new value on field A but only if field A is actually NULL.
I tried to make this with an AFTER UPDATE trigger, putting an UPDATE sentence inside, but it seems there is a transaction conflict (maybe because my update blocks the UPDATE that fires the trigger.
I know how to solve this on Oracle (just modifying the :new.A value on an AFTER INSERT trigger), but on SQL-Server 2000 I don't know how to solve it. Any help, please ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Disadvantages (Problems) of Triggers
http://blog.sqlauthority.c
Also most of the hosting company disable it.
You cannot. If you are using Oracle :-) This is "special syntax" of MSSQL.
There is a pretty good article for the join options you have with different databases at http:/articles/Database/Mi
Just a very minor change (no points please), just to allow for the time when B does not change:
CREATE TRIGGER trig_dates ON myTable
AFTER UPDATE
AS
IF UPDATED(B)
BEGIN
UPDATE tbl
SET A = new.B
FROM INSERTED new
JOIN myTable tbl ON new.id = tbl.id
JOIN DELETED old ON new.id = old.id
WHERE new.A IS NULL
AND new.B <> Old.B
END
If there is any chance that the new or old B could be Null then change:
AND new.B <> Old.B
To:
(AND new.B <> Old.B
Or (new.B IS NULL And old.B IS NOT NULL)
Or (new.B IS NOT NULL And old.B IS NULL))
That's true, acp. Totally overseen ... Under rare conditions, this might be an issue.
Why we need that? IF UPDATED(B) is triggered if the column is set in an UPDATE, even if it is unchanged or empty. As long as it remains empty (NULL), no harm would be done; but if B is filled already without triggering the code (how ever this should happen), at first update of the table with B in SET the value would be copied into A. Whether that is a bug or a feature is left to the question author.
As long as B is NULL, that value will be updated for A each time you update your table. I.e. the trigger is writing NULL into A each time.
Is there any situation were B could be filled, but with the trigger disabled temporarily, e.g. bulk inserts/copys or the like? Or records inserted with a already filled-out B?
Just forget about the specific case of NULL for now. If you only want to update A when B's value actually changes then you have to compare the before and after values as I posted. All IF UPDATED(B) tells you is that B participated in an UPDATE statement and not that its value changed.
I trust that is clear.
Business Accounts
Answer for Membership
by: greenhacksPosted on 2009-09-20 at 03:31:00ID: 25376572
I would strongly recommend to avoid using of triggers.
Adds more load on the server.
Try to handle this via code would be a better way.
Will see if i can test some trigger code when i get chance, or you can wait for anyother Expert to answer it.