| Author |
Topic |
|
ChessMaster
Starting Member
5 Posts |
Posted - 2007-09-19 : 07:51:41
|
Hi all, I have a problem. I need a query that blocks table and makes it unreadable. I decided to use WAITFOR to long blocking.BEGIN TRAN myStopReadTrans USE MyDatabaseSELECT * From dbo.AB with(readpast,updlock)WAITFOR DELAY '1:00:00'COMMIT USE MyDatabaseSelect name from dbo.Clients |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-09-19 : 08:40:28
|
| BEGIN TRAN myStopReadTrans USE MyDatabaseSELECT * From dbo.AB with(holdlock,tablockx)WAITFOR DELAY '1:00:00'COMMIT==========================================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. |
 |
|
|
ChessMaster
Starting Member
5 Posts |
Posted - 2007-09-19 : 08:50:32
|
I started big query and after that the small one... and it works like no blocks was made by first query :(BEGIN TRAN myStopReadTransUSE MyDatabaseSELECT * From dbo.Clients with(holdlock,tablockx)WAITFOR DELAY '1:00:00'COMMIT USE MyDatabaseSelect name from dbo.Clients |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-09-19 : 08:55:04
|
| What's the query on the other spid you are using to test?Are you sure you ran the transaction?==========================================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. |
 |
|
|
ChessMaster
Starting Member
5 Posts |
Posted - 2007-09-19 : 09:01:20
|
| I opened two new queries and wrote text in eache one. Than pressed "play" in big query, went to smaller one and there pressed "play". And big has 55 spid, small - 51. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
ChessMaster
Starting Member
5 Posts |
Posted - 2007-09-19 : 10:34:35
|
| I need to use QUERY WITH WAITFOR. |
 |
|
|
ChessMaster
Starting Member
5 Posts |
Posted - 2007-09-21 : 06:52:49
|
| Any ideas? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2007-09-21 : 12:37:32
|
I have to agree with Brett. Obviously, I never do this sort of thing. But, as an academic exercise I've only been successful at locking a table using an UPDATE statement. For example:SET TRANSACTION ISOLATION LEVEL SERIALIZABLEBEGIN TRANSACTIONUPDATE MyTableSET MyColumn = MyColumnWAITFOR DELAY '1:00:00'COMMIT TRANSACTION And given that it is an update you shouldn't need to set the Isolation Level either. Perhaps there are other ways...? I've seen the stored procedure called sp_getapplock, but I do not know if it actually works as advertised. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-09-23 : 20:06:07
|
| The query I gave will lock the table - I suspect there was a mistake in the OP's testing which caused him to think it wasn't.Either the transaction was terminated or the other spid was doing dirty reads.==========================================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. |
 |
|
|
|