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

  • Home
  • SEARCH
  • 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 8519249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:11:51+00:00 2026-06-11T06:11:51+00:00

I have a table BigTable and a table LittleTable. I want to move a

  • 0

I have a table BigTable and a table LittleTable. I want to move a copy of some records from BigTable into LittleTable and then (for these records) set BigTable.ExportedFlag to T (indicating that a copy of the record has been moved to little table).

Is there any way to do this in one statement?

I know I can do a transaction to:

  1. moves the records from big table based on a where clause
  2. updates big table setting exported to T based on this same where clause.

I’ve also looked into a MERGE statement, which does not seem quite right, because I don’t want to change values in little table, just move records to little table.

I’ve looked into an OUTPUT clause after the update statement but can’t find a useful example. I don’t understand why Pinal Dave is using Inserted.ID, Inserted.TEXTVal, Deleted.ID, Deleted.TEXTVal instead of Updated.TextVal. Is the update considered an insertion or deletion?

I found this post TSQL: UPDATE with INSERT INTO SELECT FROM saying “AFAIK, you cannot update two different tables with a single sql statement.”

Is there a clean single statement to do this? I am looking for a correct, maintainable SQL statement. Do I have to wrap two statements in a single transaction?

  • 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-11T06:11:53+00:00Added an answer on June 11, 2026 at 6:11 am

    You can use the OUTPUT clause as long as LittleTable meets the requirements to be the target of an OUTPUT ... INTO

    UPDATE BigTable
    SET ExportedFlag = 'T'
    OUTPUT inserted.Col1, inserted.Col2 INTO LittleTable(Col1,Col2)
    WHERE <some_criteria>
    

    It makes no difference if you use INSERTED or DELETED. The only column it will be different for is the one you are updating (deleted.ExportedFlag has the before value and inserted.ExportedFlag will be T)

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

Sidebar

Related Questions

I have table with 300 000 records (MyISAM). I get record from this table
Into : Currently i have scraped all the data into one PostgreSQL 'Bigtable' table(there
I have a large table (~10 million records) that contains several keys into other,
I have a big table containing a button in each cell. These buttons are
I have table and this table contain result column with some entries. I just
I have table View with grouped style with three sections. Get information from dictionary
I have an SQL query that executes a LEFT JOIN on another table, then
I have pretty big table with lots of columns. I want to find all
i have a big table and need to set CSS-classes on it etc. So
I have a big table with some NULLs in it. What is the easiest

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.