Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jogin malathi
Posting Yak Master
117 Posts |
Posted - 2007-04-18 : 01:14:08
|
| HiI want to write all my select ststements using locks how i should write a select ststement using locksi searched for examples but iam not getting the syntaxPlz give me one example for select statements using locksthanks in advanceMalathi Rao |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-04-18 : 01:47:52
|
| You mean you want to hold the locks?It needs to be inside a transaction and coded with holdlock. The locks will be held until the transaction is terminated.begin transelect * from tbl with (tablockx, holdlock)commit tranWhy would you want to do this though? Maybe a bit of thought would give you a better way of doing whatever it is.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jogin malathi
Posting Yak Master
117 Posts |
Posted - 2007-04-18 : 02:30:02
|
Select Source_Id,Sname,Type,Parent_Company,Nature_of_Work,Status from Source with(tablock) where Status=@statWhat is the meaning of above queryquote: Originally posted by nr You mean you want to hold the locks?It needs to be inside a transaction and coded with holdlock. The locks will be held until the transaction is terminated.begin transelect * from tbl with (tablockx, holdlock)commit tranWhy would you want to do this though? Maybe a bit of thought would give you a better way of doing whatever it is.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
Malathi Rao |
 |
|
|
jogin malathi
Posting Yak Master
117 Posts |
Posted - 2007-04-18 : 02:32:33
|
Select Source_Id,Sname,Type,Parent_Company,Nature_of_Work,Status from Source with(tablock) where Status=@statWhat is the meaning of above queryquote: Originally posted by nr You mean you want to hold the locks?It needs to be inside a transaction and coded with holdlock. The locks will be held until the transaction is terminated.begin transelect * from tbl with (tablockx, holdlock)commit tranWhy would you want to do this though? Maybe a bit of thought would give you a better way of doing whatever it is.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
Malathi Rao |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-04-18 : 02:48:48
|
| It'll take a shared lock on the table for the select then release it - doubt if it does what the coder expects.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|