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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row Locking

Status
Not open for further replies.

ryan

Programmer
Nov 13, 2000
73
US
I'm having a hard time trying to figure out how to lock a row within SQL 2000. Basically I want to lock a row with a specific lock type (i.e. exclusive) and then unlock it, how might one do this on a simple select statement for example?

Thanks,
Ryan
 
Hello Ryan,

This is an interesting question. It sent me to the SQL Server Books Online where I learned that SQL Server handles locking automatically;

that Locking Hints can be used in a SELECT statement, for example
Code:
SELECT au_lname FROM authors WITH (ROWLOCK)

that exclusive locks are used by SQL Server this way:"Exclusive (X) Used for data-modification operations, such as UPDATE, INSERT, or DELETE. Ensures that multiple updates cannot be made to the same resource at the same time."

and that this is a big topic.




 
The above will work, however why do you need to lock the row. Generally this is not needed in sql server if you are using transactions properly. Can you outline what you are doing?
 
You can try also transactions
begin transactions
--do something
if someBadThere then
begin
rollback transaction
end
commit transaction John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top