Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Lock INSERT for record with specific values.
Message
From
13/06/2003 05:39:05
 
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00799326
Message ID:
00799696
Views:
27
Hi Michael,

probably I want to make what MSQL cannot make.

However:

my demand is the contrary:

a SELECT must block commandos INSERT made on other sessions, only for commandos INSERT who contain a value used in the WHERE of the SELECT.

Example:
--SESSION 1
DECLARE @rowsType1 TINYINT
SET @rowsType1=1 
-- time = tStart
SELECT MAX(field1) FROM myTable WITH(HOLDLOCK) WHERE field2=@rowsType1
-- i want MAX(field1) not change for @rowsType1 rows group.
.....
COMMIT
-- time = tEnd

--SESSION 2
-- time : t with tStart<t<tEnd
INSERT INTO myTable (field1,field2) VALUES(34,2)
-- this can insert without lock

--SESSION 3
-- time : t with tStart<t<tEnd
INSERT INTO myTable (field1,field2) VALUES(34,1)
-- this is locked until t>tEnd
I declare index for field1 and field2, but INSERT on SESSION 2 is locked.

If you want, i build a example for you to test on MS QUERY.

Fabio
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform