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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:36:35+00:00 2026-06-04T06:36:35+00:00

i have two tables: new_table id | parentid | f1 | f2 | customerid

  • 0

i have two tables:

new_table

id | parentid | f1 | f2 | customerid

initial_table (does not have customerid)

id | parentid | f1 | f2

what i need to do is move ALL items from initial_table to new_table. however, id’s change (auto generated) in the new_table!

—

so, my idea (for now) is:

1 – move all data except id and parentid from initial_table to new_table

2 – use a lookup_table with

id | originalparentid | newparentid | customerid

3 – go through the lookup_table and update the new_table parentid column with the new parentid‘s

—

so…

question – 1 – is this the right way?

question – 2a – if yes, how to do it?

question – 2b – if no, how then?

the problem in 2 is that i am doing this from a trigger and customerid is SELECT @customerid = id FROM inserted and this is fine. then i am doing

INSERT INTO new_table (f1, f2, customerid)
SELECT f1, f2 @customerid FROM initial_table

but i don’t get the new id’s from new_table when i do it like that.

—

so, please, help me write this trigger:

i need to copy all data from initial_table to new_table with the problem that the id’s will change and i need to update the parentid’s accordingly in the new_table

thnx

—

here is my current trigger:

ALTER TRIGGER Copy
ON dbo.Customers

FOR INSERT
AS

BEGIN TRANSACTION

/* variables */
DECLARE
    @customerid bigint

SELECT @customerid = id FROM inserted

/* insert all for this customer */
INSERT INTO new_table (f1, f2, customerid)
    SELECT f1, f2 @customerid FROM initial_table

/* TODO: add entries to lookup table */

/* TODO: fix the pages' parentid's */

/* execute */
COMMIT TRANSACTION

GO
  • 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-04T06:36:36+00:00Added an answer on June 4, 2026 at 6:36 am

    I would just turn IDENTITY INSERT off for the initial insert and avoid this whole mess. Is there any reason you can’t do that? Something like this should do it:

    SET IDENTITY_INSERT dbo.Customers ON
    

    Then when you are done just run

    SET IDENTITY_INSERT dbo.Customers OFF
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to MySQL and PHP. I have two tables, one to hold all
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables: `temp_info` and `paid_info` Upon successful payment, I want data from
I have two tables with some ID's and I need a query that returns
High level I have two tables that need to have some of the data
I am trying to import data from a large database. I have two tables
I have two large tables and want to combine all of the column names
I have two tables: products products_tmp The products_tmp table has less fields. But all
i have two tables products and reviews each product has several reviews linked by
I have two tables on a webform. On a button click I want 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.