February 18, 2013 at 12:22 am
i have one table, concurrently multiple users are hiting the table through insert action.
i have placed trigger on the table to have check uniqueness with multiple fields within the table.
As concurrent users are inserting records in the table at the same time with difference of mili seconds that trigger is not be able to check the duplicity while inserting records.
pls suggest...
February 18, 2013 at 5:50 pm
1. Revise the code to implement the best practices.
2. Make sure you have appropriate indexes in place and your code in trigger uses it.
Having these conditions fulfilled you should not have trouble with multiple calls within milliseconds.
I saw 10 SP calls completed successfully within 0.01 s on a 10 years old server running SQL2000. And those procedures were not ideal ones in terms of optimisation.
_____________
Code for TallyGenerator
February 27, 2013 at 8:58 am
thanks for the comments 🙂
will try this and get back
February 27, 2013 at 9:34 am
You should use a unique constraint instead of a trigger to check for this type of thing.
http://msdn.microsoft.com/en-us/library/ms191166.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
March 1, 2013 at 10:57 pm
thanks for your kind reply:-)
agreed, constraint can be used instead of trigger.
but the requirement is something different, if i use constraint it will check the defined uniqueness within the table and raise error or rollback the process. which i don't want to do, I want to simply check if the duplicity and if found do nothing (nor insertion of record).
March 4, 2013 at 7:42 am
vinodkel (3/1/2013)
thanks for your kind reply:-)agreed, constraint can be used instead of trigger.
but the requirement is something different, if i use constraint it will check the defined uniqueness within the table and raise error or rollback the process. which i don't want to do, I want to simply check if the duplicity and if found do nothing (nor insertion of record).
While I don't condone this approach you could use an INSTEAD OF INSERT trigger. Your trigger body would simply be an insert where not exists. The performance will likely be slower than a unique constraint but it would solve the issue.
A better approach might be to use an insert stored proc that only inserts the valid data. This could be a great place for a MERGE, the good rows get inserted and the duplicates get logged.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply