Answered by:
LOCK/Wait on Begin Tran and Commit

Question
-
Hi,
We have a script with insert statements in between BEGIN TRANSACTION and COMMIT.The data from those insert statements should populate few tables. When two of us run the script at the same time. Some of my data and some of other persons data are getting populated. I would like to know the best option to get rid of this issue. Should we use NOLOCK or Wait or any other approach that is the best.Can somebody suggest?
Thanks
BRP
Tuesday, October 8, 2013 2:05 PM
Answers
-
How about
insert into table with (TABLOCK) select * from anothertable
Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
SQL Server Integration Services: Business Intelligence
- Proposed as answer by Shanky_621MVP Friday, October 25, 2013 1:16 PM
- Marked as answer by Chongtham Rajen Singh Sunday, November 3, 2013 12:04 PM
Tuesday, October 8, 2013 2:12 PMAnswerer
All replies
-
How about
insert into table with (TABLOCK) select * from anothertable
Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
SQL Server Integration Services: Business Intelligence
- Proposed as answer by Shanky_621MVP Friday, October 25, 2013 1:16 PM
- Marked as answer by Chongtham Rajen Singh Sunday, November 3, 2013 12:04 PM
Tuesday, October 8, 2013 2:12 PMAnswerer -
Hello ,
You cannot use NOLOCK query hint with DML and merge statement.
You can think of using TABLE LOCK in query but need to test it first.
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
- Proposed as answer by Shanky_621MVP Friday, October 25, 2013 1:16 PM
Tuesday, October 8, 2013 2:14 PM -
oh. Yes. But I have 8 tables getting inserted one after the other. So, do u suggest using tablock on each insert statement. Or do u think we should use SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
BRP
- Marked as answer by Chongtham Rajen Singh Sunday, November 3, 2013 12:04 PM
- Unmarked as answer by Shanky_621MVP Sunday, November 3, 2013 4:20 PM
Tuesday, October 8, 2013 2:35 PM -
- When two of us run the script at the same time. Some of my data and some of other persons data are getting populated. I would like to know the best option to get rid of this issue.
What issue? Can you provide sample code and explain what you are trying to achieve?
Two concurrent transactions can typically insert data into the same tables. Are you trying to prevent that?
David
David http://blogs.msdn.com/b/dbrowne/
- Edited by davidbaxterbrowneMicrosoft employee Tuesday, October 8, 2013 2:38 PM
Tuesday, October 8, 2013 2:37 PM