SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


using locks in sql server 2005


using locks in sql server 2005

Author
Message
vinodkel
vinodkel
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 46
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...
Sergiy
Sergiy
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10214 Visits: 11958
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.
vinodkel
vinodkel
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 46
thanks for the comments :-)

will try this and get back
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25815 Visits: 17509
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
vinodkel
vinodkel
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 46
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).
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25815 Visits: 17509
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search