Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

I am in a confusion that whether SQL Server 2008 makes lock on tables during insertion,deletion, update and selection on its own OR we have to place lock on tables on which we are performing the DML operations.

As I have to insert data into the table and at the same time I have to fetch the serial no of the same record for updating the other table on the basis of that table.

And also please let me know that what lock must be put on the table during insertion.

Thanks

Varun Sareen
Posted

Yes Sql server 2008 place a lock on a table during CRUD operation (Insert , Select , Update , Delete) by its own.

but As per my knowledge you should be fine with your flow.
 
Share this answer
 
you do not have to place locs explicitly for Select / Insert / Update or Delete operation. SQL Server do it by itself.

But you can place (NOLOCK) while you are reading / selecting the table so that it will not effect other operations.

Thanks
 
Share this answer
 
Hi varun,

Do you want the serial number before insertion of record or after the insertion of the record.

you can get the serial number once record is inserted successfully.
 
Share this answer
 
if you just want to fetch the serial number and if you have that
identity

Serial Number  int identity(1,1))

  //you can try this 

INSERT INTO tbl1(val1, val2, val3 ...) VALUES(@val1, @val2, @val3...); 
SELECT SCOPE_IDENTITY(); 


For Lock try this Link

ClickHere[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900