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 |
|
sajsal
Starting Member
4 Posts |
Posted - 2004-02-07 : 05:20:11
|
| I have applied a trigger on inserts of a table. The triger might execute for 10 or even more seconds depending upon the data in the table. The trigger also affect other tables as well.When a record is inserted into the table, the triger fires and starts executing. Now suppose that as soon as the trigger fires, another record is inserted. Logically, another instance of the trigger must fire and start executing. Now what I want to know is a method that stops other instance to start after the first finishes. In simple words only one instance of the trigger must execute at one time.A code example will be appreciated alot.regardsSajid |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-02-07 : 09:27:40
|
| What are you trying to accomplish in your trigger? |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-07 : 09:59:21
|
| How about to create a tiny one-row table:create table trigger_status (st bit)insert into trigger_status select 0Then, in the trigger body, check it:ASif (select top 1 st from trigger_status with(nolock))=0beginupdate trigger_status set st=1{here "main" part of the trigger}update trigger_status set st=0end |
 |
|
|
sajsal
Starting Member
4 Posts |
Posted - 2004-02-09 : 05:04:31
|
| Thank you Stoad for your reply.Idea is great, BUTTwhen the second instance will execute, it will perform nothing. I want the trigger to perform all the processing for each insert. Any ideasThanksSajid |
 |
|
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2004-02-09 : 07:03:59
|
| OK. How about to check it in a while loop?ASwhile (select top 1 st from trigger_status with(nolock)) <> 0waitfor delay '00:00:00.05'beginupdate trigger_status set st=1 |
 |
|
|
|
|
|