Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:24:25+00:00 2026-06-18T11:24:25+00:00

From a table like this: ID SEQUENCE 1 1 I want to increment the

  • 0

From a table like this:

ID  SEQUENCE
1    1

I want to increment the sequence value each time the table is accessed. So far I came up with this vbscript:

Dim Result
On Error Resume Next
Result = GetSequential()
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.CreateTextFile("result_" & Result & ".txt", False)
if err.Number <> 0 then
   MsgBox err.Description & " (" & Err.Number & "): " & Result
end if
on error goto 0
wscript.echo "Next value: " & Result

Function GetSequential()
Dim cn, rs
Dim Sequential

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.connectionstring = "Driver={MySQL ODBC 5.2a Driver};Server=172.16.0.130;Database=testautostore;User=root;Password=aquilae"
cn.Open

Dim SqlCount
SqlCount = "select count(*) from counter where ID='1'"
rs.Open SqlCount, cn, adOpenStatic

If rs(0) = "1" Then 
    wscript.echo "Updating record..."
    Dim SqlUpdate
    SqlUpdate = "update counter set SEQUENCE=SEQUENCE + 1 where ID='1'"
    cn.Execute SqlUpdate

    Dim SqlSelect
    SqlSelect = "select SEQUENCE from counter where ID='1'"
    rs.Close
    rs.Open SqlSelect, cn, adOpenStatic

    Sequential = rs(0)
    wscript.echo "Result: " & Sequential
End if

rs.Close
Set rs = Nothing
cn.Close

GetSequential = Sequential
End Function

This works fine when run individually:

cscript testsequence.vbs

but when running it several times simultaneously then is not guaranteed to get a unique sequence number. This is apparent when launching a batch file like this:

for /l %%x in (1, 1, 25) do start cscript testsequence.vbs

which produces exception failures when creating the result_?.txt files as a result of returning the same sequence value (File already exists).

So the question is how can I lock the table update operation?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:24:26+00:00Added an answer on June 18, 2026 at 11:24 am

    You seem to assume that the update and read in your script will be atomic:

    • process A updates sequence
    • process A reads sequence
    • process B updates sequence
    • process B reads sequence

    MySQL, however, has autocommit enabled by default, so each statement is run by itself, and queries from concurrent processes may become intermingled:

    • process A updates sequence
    • process B updates sequence
    • process B reads sequence
    • process A reads sequence

    That way A and B will read the same value, although both processes incremented it.

    You need to put your statements in a transaction and use an appropriate isolation level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a table like this Generated from three database tables depends
MY query looks like this: SELECT COUNT(entryID) FROM table WHERE date >= DATE_SUB(CURDATE(), INTERVAL
I like to have a query like this: select data from table where (x
I am trying to do something like this: select char_length(select text_field from table where
I've got a query that looks something like this: SELECT * FROM table WHERE
Is it possible to accomplish something like this using linqtosql? select * from table
I have a select like this: SELECT field1, field2, field3 FROM table WHERE field1=
I have a MySQL query like this SELECT id,seq,text FROM table ORDER BY seq
I have a sql like this: SELECT TOP 1 field_name * FROM table_name and
I found it in a statement like this: delete /*+ restrict_all_ref_cons */ from table_1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.