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 8320017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:30:55+00:00 2026-06-08T22:30:55+00:00

I am just now starting to dig into Teradata’s locking features and Google is

  • 0

I am just now starting to dig into Teradata’s locking features and Google is fairly convoluted with explanations on this. Hopefully, I can get a very simple and streamlined answer from SE.

After encountering numerous issues with identity columns in Teradata, I’ve decided to create a mechanism that mimics Oracle’s sequence. To do this, I am creating a table with two fields, one that holds a table name and the other that stores its last-used sequence. I am going to then create a stored procedure that takes a table name. Within the procedure, it will perform the following options:

  • Select the last-used sequence from the sequence table into a variable (select LastId from mydb.sequence where tablename = :tablename)
  • Add 1 to the variable’s value, thus incrementing it
  • Update the sequence table to use the incremented value
  • Return the sequence variable to the procedure’s OUT param so I can access the sequenced ID in my .NET app

While all of those operations are taking place, I need to lock the sequence table for all read and write access to ensure that other calls to the procedure do not attempt to sequence the table while it is currently in the process of being sequenced. This is obviously to keep the same sequence from being used twice for the same table.

If this were .NET, I’d use a Sync Lock (VB.NET) or lock (C#) to keep other threads from entering a block of code until the current thread was finished. I am wondering if there’s a way to lock a table much in the same way that I would lock a thread in .NET.

  • 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-08T22:30:58+00:00Added an answer on June 8, 2026 at 10:30 pm

    Consider using an explicit locking mechanism for a rowhash lock for the transaction:

    BEGIN TRANSACTION;
    
    LOCKING ROW EXCLUSIVE
    SELECT LastId + 1 INTO :LastID
    FROM MyDB.SequenceCols
    WHERE TableName = :TableName
      AND DatabaseName = :DatabaseName;
    
    UPDATE MyDB.SequenceCols
    SET LastId = :LastID
    WHERE TableName = :TableName
      AND DatabaseName = :DatabaseName;
    
    END TRANSACTION;
    

    The rowhash lock will allow the procedure to be used by other processes against other tables. To ensure row level locking you must fully qualify the primary index of the SequenceCols table. In fact, the primary index of the SequenceCols table should be UNIQUE on DatabaseName and TableName.

    EDIT:

    The exclusive rowhash lock would prevent another process from reading the row until the END TRANSACTION is processed owner of the rowhash lock.

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

Sidebar

Related Questions

I am starting with google maps. just learning. while ago, it was working. now
I'm just now starting to dive into IF statements in R . From what
I'm just now starting to get into the idea of threading, and wanted to
I am just now starting to use version control and my head is spinning!
With relative newness to AJAX, and now just starting to learn PDO, the added
I'm just starting web-developing now (I do have experience with C#). And I've seen
Or the concepts/best practices used there are now deprecated? I'm just starting to use
So I'm starting my first actual Program in C# now, and just before I
I am just now starting to work with LINQ, and am pretty familiar with
I am now starting to get back to C++ coding (just for fun), and

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.