Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two inserts at the same time 3

Status
Not open for further replies.

iwease

IS-IT--Management
Sep 4, 2006
104
CA
Hi,

I have a couple questions about what happens when people insert at the same time


Case 1
Suppose that I have a table and two different users. User 1 does a bulk insert in the table. While this bulk insert is being performed, User 2 inserts a record. Will User 2's record appear at the end of the bulk insert, at the beginning of the bulk insert, or in the middle?

Case 2
Suppose that I have a table and two different users. User 1 opens a transaction and does a bunch of separate insert statements. While User 1 is preforming these statements, User 2 inserts a record. Again, will User 2's record appear at the end of the bulk insert, at the beginning of the bulk insert, or in the middle?

Thanks a bunch
 
what I mean is, assuming my primary key is an identity column, will the insert from user 2 have an identity that is greater then those from user 1's bulk insert, less then, or inbetween (ie...user 1 has some records with an ID lower than user 2's and some records with an ID above)
 
A bulk insert is run as one big batch. so in case #1 user 2's Ids would be higher than user 1.

In case #2 it depends on who aquires the locks first.

Look up ACID properties in BOL. It will help you understand how transactions work.

- Paul [batman]
- If at first you don't succeed, find out if the loser gets anything.
 
ok...so since I am either using a bulk insert or a transaction, User 2's inserted record will never appear with an ID that is between User 1's minimum and maximum ID

Right?
 
Also throw into the works, are you doing any kind of locking on your table. And if so, what kind of locking. Again, take a look at BOL and search for lock hints. IF your entire table is locked, no other user will be able to do anything until th elock is released. This means that user1's data will be inserted, the table/page/row/etc unlocked, then user2 can insert.

It also depends on who access athe table first. I know this is a very basic description of locking. BOL has a pretty good description of what goes on.
 
What is BOL? I'm assuming it is some sort of reference?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top