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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:37:43+00:00 2026-05-20T08:37:43+00:00

I currently have a table like this: Stuff ———- StuffId identity int not null

  • 0

I currently have a table like this:

    Stuff
    ----------
    StuffId identity int not null
    Description nvarchar(4000) null
    ...

I want to store the Description in a separate table that I have set aside specifically for user-generated content:

    Content
    ----------
    ContentId identity int not null
    Content nvarchar(max) not null
    ...

(this table already exists, and other tables already reference entries in it.)

So I need to:

  1. Create a DescriptionContentId field on the Stuff table with a foreign key constraint.
  2. Copy the current Description content into the Content table.
  3. Set each DescriptionContentId to have the ContentId value that was automatically generated when inserting values in step 2.
  4. Drop the Description column.

I know how to do steps 1 and 4, but steps 2 and 3 are eluding me, because they need to be done pretty much simultaneously. This seems like it would be a fairly common schema change. What’s the best way to do it?

Update

I’m a step closer thanks to the Output keyword, but I’m still missing something. Here’s what I’d like to do:

create table #tmp (StuffId int, ContentId int)

insert into Content(Content)
output s.StuffId, inserted.ContentId
into #tmp(StuffId, ContentId)
    select Description
    from Stuff s
    where Description IS NOT NULL

But I can’t reference s.StuffId because it isn’t one of the fields inserted into the Content table. How can I correlate the ID of the Stuff with the ID of the Content as I’m inserting a new Content item for each Stuff entry?

  • 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-05-20T08:37:43+00:00Added an answer on May 20, 2026 at 8:37 am

    The output clause will come to your rescue.

    It will output the description and the identity column from the insert into a table varaible and then you can use that data to update the other table.

    If description is not unique, you may have to do the following:
    add a column for the stuffID column to the content table. Then output the stuffid and content id from the insert, update the table using the stuffid to ensure uniqueness, Drop the stuffid column from the content table.

    an example from Books Online as to how to use the OUTPUT

    DECLARE @MyTableVar table(
      LastName     nvarchar(20) NOT NULL,
      FirstName    nvarchar(20) NOT NULL,
      CurrentSales money NOT NULL
      );
    
    INSERT INTO dbo.EmployeeSales (LastName, FirstName, CurrentSales)
      OUTPUT INSERTED.LastName, 
             INSERTED.FirstName, 
             INSERTED.CurrentSales
      INTO @MyTableVar
        SELECT c.LastName, c.FirstName, sp.SalesYTD
        FROM HumanResources.Employee AS e
            INNER JOIN Sales.SalesPerson AS sp
            ON e.EmployeeID = sp.SalesPersonID 
            INNER JOIN Person.Contact AS c
            ON e.ContactID = c.ContactID
        WHERE e.EmployeeID LIKE '2%'
        ORDER BY c.LastName, c.FirstName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently we have a table that we use to track inivitations. We have an
Currently I have a table that I search upon 4 fields, FirstName, LastName, MiddleName,
I have a table with almost 800,000 records and I am currently using dynamic
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
I have a sqlite (v3) table with this column definition: timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
I have a question about tables in MySQL. I'm currently making a website where
I have a pretty standard table set-up in a current application using the .NET
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have speakers set up both in my office and in my living
I currently have an existing database and I am using the LINQtoSQL generator tool

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.