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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:07:07+00:00 2026-05-30T10:07:07+00:00

I am migrating data from a series of old data tables to new tables.

  • 0

I am migrating data from a series of old data tables to new tables. In this process I came upon some issues.

I need to create a table, copy some data from old table to new one then drop old table. To achieve this, I need to write a script that does not show errors even if you run it on a migrated database, meaning even if the old tables are not there I should not see errors and simply skip the process.

Following is what I came up with up to now:

IF NOT EXISTS(SELECT * FROM sys.objects WHERE Object_ID = Object_ID('Old_Table'))
    GOTO Migrated_Before

  -- Drop OldTable Indexes, PK's and FK's;
  -- CREATE newTable ....;
  -- Add Indexes, PK's, Fk's;
  -- INSERT INTO NewTable(someFields) FROM OldTable.Fields, OtherTable.Fields ...;
  -- DROP OldTable;

Migrated_Before:

Here is the issue, Drop and Create need GO to commit changes before continue to next stage otherwise, next command will fail, however putting GO between GOTO and Label will make label undefined for GOTO.

How can I force each process to run before continue to next one without writing IF multiple times?

Solution: I leave the solution here as reference for others.
I added begin transaction before every statement that need to happen before proceeding to next statement, for example, create table or drop FK’s. and also replaced goto and label with begin end (my first solution)

  • 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-30T10:07:08+00:00Added an answer on May 30, 2026 at 10:07 am

    Try using begin transaction, commit instead of go

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

Sidebar

Related Questions

I'm migrating data from an old laptop to a new laptop, including some vb.net
I'm migrating some data from DNN to another platform, and need a way to
I'm migrating some data from one oracle schema/table to a new schema/table on the
I'm migrating data between tables in Access 2003. In the old table, the date
I'm migrating data from a legacy database that has many tables with primary keys
this is my question: I'm migrating data from a Btrieve file (.dat) through Pervasive
I am working on migrating a bunch of data from an old database into
I am in the process of migrating legacy data to a new system. I
I am migrating data from one database schema to another. The old schema has
I am in the process of migrating a large amount of data from several

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.