Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
using locks in sql server 2005
using locks in sql server 2005
Rate Topic
Display Mode
Topic Options
Author
Message
vinodkel
vinodkel
Posted Monday, February 18, 2013 12:22 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, April 01, 2013 5:31 AM
Points: 3,
Visits: 26
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...
Post #1421048
Sergiy
Sergiy
Posted Monday, February 18, 2013 5:50 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 3:04 PM
Points: 4,551,
Visits: 8,202
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.
Post #1421394
vinodkel
vinodkel
Posted Wednesday, February 27, 2013 8:58 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, April 01, 2013 5:31 AM
Points: 3,
Visits: 26
thanks for the comments
will try this and get back
Post #1424584
Sean Lange
Sean Lange
Posted Wednesday, February 27, 2013 9:34 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:33 PM
Points: 8,620,
Visits: 8,261
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 Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1424602
vinodkel
vinodkel
Posted Friday, March 01, 2013 10:57 PM
Forum Newbie
Group: General Forum Members
Last Login: Monday, April 01, 2013 5:31 AM
Points: 3,
Visits: 26
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).
Post #1425820
Sean Lange
Sean Lange
Posted Monday, March 04, 2013 7:42 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:33 PM
Points: 8,620,
Visits: 8,261
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 Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1426254
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.