473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How can i lock the row of a table ?

Hi,
Let's assume I 've a table and want to select the first 10 rows from
that table but I want to be sure that no other scripts will select the
same rows I've previously got by the first script.

How can I do that?

my table contains one primary key. Let's say id is the column name.
So my first script is running and select the ids: 1, 2, 3 .... 10

Then that script will play with the returned ids.
In the same time, I'm running a second script and do the same select.
But I don't want him to get the first 10 ids.

How can i lock the row table?
please help me thanks in advance....
Apr 21 '11 #1
2 1799
code green
1,726 Expert 1GB
Simplest way is an additional boolean field which is flagged by an UPDATE from the IDs selected.
Apr 21 '11 #2
dlite922
1,584 Expert 1GB
Wrong! Update and boolean field will create a race condition and can fail.

For your locking to be effective each script needs to write-lock the entire table until it read those X number of lines.

Since each script can take less than a second to read those lines, you do not notice a performance degradation.

With @codegreen's suggestion, you will be querying the database twice and will definitely lose performance.


Dm
Apr 22 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: leecho | last post by:
Hi, recently, i was assigned as a new dba for our system. I found that my statistic keep change from time to table. To look for the cause, i wanna to lock a table, means only allow user to...
0
by: Colleyville Alan | last post by:
My app is giving me this error. Run-time error 3211: The database engine could not lock table 'Sorted_Template' because it is already in use by another person or process. When I run the app...
0
by: volumstein | last post by:
I have a make-table query in a FOR loop that outputs to 'table1.' 'table1' is then referenced by 'Form1.' here's the code: For j = 1 To rsTable.RecordCount SerialNumRef.Value =...
1
by: Sandy | last post by:
Hi I want to lock a table using JDBC as I want to perform some query's (read and write) in exclusive mode. Different threads will be executing the same code simultaneously. I am using the...
2
by: simonZ | last post by:
I create a transaction: sqlTran=sqlConn.BeginTransaction(IsolationLevel.Serializable); Then, I insert some data into report table with sqlCommand object: oCmd = new...
0
by: sang | last post by:
Hi I want to lock the table with both read and write there is no action held after lock the table. I know how to lock the table with read and write, lock table mytable read; lock table...
3
by: Himmel | last post by:
I have added a section of code to a function that is designed to copy data from several tables and place them into a single table. The new table already contains a unique ID and name, and I am...
1
by: tembil | last post by:
Hi, can anyone plz help me, I'm trying to insert data into a table from another table and I'm getting this error: The total number of locks exceeds the lock table size, how can I fix this. thanx
2
by: robert stearns | last post by:
When I use LOCK TABLE ... COMMIT, must I also use odbc_autocommit(dbConn, FALSE)? In other words will auto commit prematurely defeat the LOCK TABLE?
3
by: Frederick Tant | last post by:
DB2 V9.7 The DB is used by 1 application with no concurrent applications. I got the problem that large update/insert cause lock escalation, to solve the issue I set a lock on the table so...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.