472,358 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

How do you lock an entire table?


Hi,
I need to lock a table so that Inserts are prevented as well as deleted and
updates. At present I'm thinking this might do it:

SELECT * FROM myTable WITH(UPLOCK)

but then again I'm not sure whether this will cover the insert case.

Thanks,

Robin
Jul 23 '05 #1
5 2887
Robin Tucker (id*************************@reallyidont.com) writes:
I need to lock a table so that Inserts are prevented as well as deleted
and updates. At present I'm thinking this might do it:

SELECT * FROM myTable WITH(UPLOCK)

but then again I'm not sure whether this will cover the insert case.


To cover inserts, you need the serializable isolation level, and as far
as I know, that is what UPDLOCK buys you. Testing is always a good idea,
though.

It would be interesting to know why you think you need to lock the entire
table. It may be the right thing to do, but it sounds a little funny.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

Yes, it is funny indeed. The basic situation is that I was spec'd to write
a "single user/client" system, installing MSDE on the client PC along with
the client software. All of a sudden "multi-user" is a basic product
requirement, although I didn't write a core suitable for concurrency (this
is kindof a real-time system, so concurrency really needed to be designed in
from the start. So, as a stop-gap measure, I am wanting to lock a table,
write a "I'm using this now" record, unlocking it when the user times out or
logs off. Okay, this is dumbass I know, but it will take 4 months to
rewrite the core to use the correct design pattern for this new
requirement - this is a quick "hack" to get things up and running pending
the new core ;)
"Erland Sommarskog" <es****@sommarskog.se> wrote in message
news:Xn**********************@127.0.0.1...
Robin Tucker (id*************************@reallyidont.com) writes:
I need to lock a table so that Inserts are prevented as well as deleted
and updates. At present I'm thinking this might do it:

SELECT * FROM myTable WITH(UPLOCK)

but then again I'm not sure whether this will cover the insert case.


To cover inserts, you need the serializable isolation level, and as far
as I know, that is what UPDLOCK buys you. Testing is always a good idea,
though.

It would be interesting to know why you think you need to lock the entire
table. It may be the right thing to do, but it sounds a little funny.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 23 '05 #3
Robin Tucker (id*************************@reallyidont.com) writes:
Yes, it is funny indeed. The basic situation is that I was spec'd to
write a "single user/client" system, installing MSDE on the client PC
along with the client software. All of a sudden "multi-user" is a basic
product requirement, although I didn't write a core suitable for
concurrency (this is kindof a real-time system, so concurrency really
needed to be designed in from the start. So, as a stop-gap measure, I
am wanting to lock a table, write a "I'm using this now" record,
unlocking it when the user times out or logs off. Okay, this is dumbass
I know, but it will take 4 months to rewrite the core to use the correct
design pattern for this new requirement - this is a quick "hack" to get
things up and running pending the new core ;)


If the table is only there to act as a locking mechanism, I strongly
recomend you to look at application locks instead. Look up
sp_getapplock and sp_releaseapplock in Books Online.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
You know what? We solved this problem without having to write any SQL code
at all. We are now using USB dongle with a one license per server hard
limit on it. Just a bit of code in the client required. ;)

Now....... I'm working on that multi-user core.

"Erland Sommarskog" <es****@sommarskog.se> wrote in message
news:Xn**********************@127.0.0.1...
Robin Tucker (id*************************@reallyidont.com) writes:
Yes, it is funny indeed. The basic situation is that I was spec'd to
write a "single user/client" system, installing MSDE on the client PC
along with the client software. All of a sudden "multi-user" is a basic
product requirement, although I didn't write a core suitable for
concurrency (this is kindof a real-time system, so concurrency really
needed to be designed in from the start. So, as a stop-gap measure, I
am wanting to lock a table, write a "I'm using this now" record,
unlocking it when the user times out or logs off. Okay, this is dumbass
I know, but it will take 4 months to rewrite the core to use the correct
design pattern for this new requirement - this is a quick "hack" to get
things up and running pending the new core ;)


If the table is only there to act as a locking mechanism, I strongly
recomend you to look at application locks instead. Look up
sp_getapplock and sp_releaseapplock in Books Online.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 23 '05 #5
Robin Tucker (id*************************@reallyidont.com) writes:
You know what? We solved this problem without having to write any SQL
code at all. We are now using USB dongle with a one license per server
hard limit on it. Just a bit of code in the client required. ;)


Ah, creative solutions! I like that!

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Holliingsworth | last post by:
Hello: I have an Access 2K form I built from a SQL Server 7.0 view. I want to lock certain fields in the database from users so they can see them on the views and forms, but NOT be able to edit...
3
by: rkusenet | last post by:
Hi, Version Info: SQLSERVER 2000 SP3 I am trying to understand how SQL Server works with SERIALIZABLE read. I am fairly new to SQL Server, having mainly worked with Informix. We are getting...
2
by: xixi | last post by:
i am using type 4 driver with fp3 on windows 64bit server, auto commit is true, cursor is CS type. i have a sensitive , updatable cursor open and bring back a one row resultset, i get this...
5
by: xixi | last post by:
hi, i am using db2 udb v8.1 on windows, i create a index on a unique value column on a table to try to create row lock, here is what i do , sql = select value from table where id=1 for update,...
0
by: Bruce Pullen | last post by:
DB2 v7.2 (FP7 - DB2 v7.1.0.68) on AIX 5.2.0.0. We're seeing unexpected single row (then commit) insert locking behaviour. We're seeing Applications that already hold row-level W locks in...
8
by: Roy Padgett | last post by:
I have a combo box where users select the customer name and can either go to the customer's info or open a list of the customer's orders. The RowSource for the combo box was a simple pass-through...
5
by: Seeker | last post by:
Hello, I've read conflicting posts about . Does it or does it not lock the entire object? In my simple test it appears to block just the method but I wouldn't exactly call my meager test...
9
by: kavallin | last post by:
I receives the following in the db2diag.log file many times / day : 2007-03-05-14.55.24.836553+060 E12415C457 LEVEL: Warning PID : 2785 TID : 1 PROC :...
6
by: michael.spoden | last post by:
Hi, how can I fix lock-waits during an online backup? Is an online backup in DB2 V8.2 not realy online? I'm using DB2 V8.2 Fixpak 15 on Linux. The command to perform the backup is: db2 backup...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.