Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

using locks in sql server 2005 Expand / Collapse
Author
Message
Posted Monday, February 18, 2013 12:22 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 17, 2014 8:31 AM
Points: 12, Visits: 39
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
Posted Monday, February 18, 2013 5:50 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, July 20, 2014 5:23 PM
Points: 4,576, Visits: 8,341
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
Posted Wednesday, February 27, 2013 8:58 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 17, 2014 8:31 AM
Points: 12, Visits: 39
thanks for the comments

will try this and get back
Post #1424584
Posted Wednesday, February 27, 2013 9:34 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:21 PM
Points: 13,083, Visits: 11,918
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
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1424602
Posted Friday, March 1, 2013 10:57 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, April 17, 2014 8:31 AM
Points: 12, Visits: 39
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
Posted Monday, March 4, 2013 7:42 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:21 PM
Points: 13,083, Visits: 11,918
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
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1426254
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse