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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:49:24+00:00 2026-06-11T02:49:24+00:00

Considering these tables: CREATE TABLE Status (current_partition INT) — has a single row CREATE

  • 0

Considering these tables:

CREATE TABLE Status (current_partition INT) -- has a single row
CREATE TABLE RecordedValues (partition INT, value INT)

Let’s say there are multiple clients that frequently insert into the RecordedValues table using the current_partition, e.g.:

DECLARE @current_partition INT
SET @current_partition = (SELECT TOP 1 current_partition FROM Status)
INSERT RecordedValues VALUES (@current_partition, 132)

Concurrently, there is a client which (periodically) modifies the current_partition, then reads all values with the old partition value, e.g.:

DECLARE @old_partition INT
SET @old_partition = (UPDATE Status 
    SET current_partition += 1 
    OUTPUT deleted.*)
--
SELECT * FROM RecordedValues WHERE partition = @old_partition

How can I ensure the latter client really selects all the rows with the old partition value? In other words, I need to ensure no INSERTs will be committed after the SELECT returns.

  • 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-11T02:49:26+00:00Added an answer on June 11, 2026 at 2:49 am

    Run your commands in a transaction, and set the isolation level to REPEATABLE READ:

    BEGIN TRANSACTION
    
    SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
    
    DECLARE @old_partition INT
    SET @old_partition = (UPDATE Status 
        SET current_partition += 1 
        OUTPUT deleted.*)
    --
    SELECT * FROM RecordedValues WHERE partition = @old_partition
    
    COMMIT TRANSACTION
    

    This will ensure consistency between the statements within your transaction.

    To quote the docs:

    “Specifies that statements cannot read data that has been modified but not yet committed by other transactions and that no other transactions can modify data that has been read by the current transaction until the current transaction completes.”

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

Sidebar

Related Questions

First execute these tables and data dumps :- CREATE TABLE IF NOT EXISTS `Tags`
I have an ai_order table. CREATE TABLE `ai_order`( `id` INT(11) NOT NULL AUTO_INCREMENT, `product_id`
I have a table like the following one CREATE TABLE [dbo].[MyTable]( [MyTableID] [int] IDENTITY(1,1)
Considering this code with 3 differents function call semantics: void f(void){ puts(OK); } int
My application has one table called 'events' and each event has approx 30 standard
I need to create a database solution to provide product discounting. Current tables: Products
Lets say that I have two tables. Table 1 is a list of vendors
I'm attempting to create a grid of availability from a number of tables to
In our database we have tables which have no single auto-increment primary key but
I've learned that views can be used to create custom table views (so to

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.