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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:47:50+00:00 2026-05-14T14:47:50+00:00

I have two tables with 10-20 million rows that have GUID primary keys and

  • 0

I have two tables with 10-20 million rows that have GUID primary keys and at leat 12 tables related via foreign key. The base tables have 10-20 indexes each.

We are moving from GUID to BigInt primary keys. I’m wondering if anyone has any suggestions on an approach. Right now this is the approach I’m pondering:

  1. Drop all indexes and fkeys on all the tables involved.
  2. Add ‘NewPrimaryKey’ column to each table
  3. Make the key identity on the two base tables
  4. Script the data change “update table x, set NewPrimaryKey = y where OldPrimaryKey = z
  5. Rename the original primarykey to ‘oldprimarykey’
  6. Rename the ‘NewPrimaryKey’ column ‘PrimaryKey’
  7. Script back all the indexes and fkeys

Does this seem like a good approach?
Does anyone know of a tool or script that would help with this?

TD: Edited per additional information. See this blog post that addresses an approach when the GUID is the Primary: http://www.sqlmag.com/blogs/sql-server-questions-answered/sql-server-questions-answered/tabid/1977/entryid/12749/Default.aspx

  • 1 1 Answer
  • 1 View
  • 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-14T14:47:51+00:00Added an answer on May 14, 2026 at 2:47 pm

    It certainly sounds like this strategy would work — dropping the constraints, changing the column out from underneath them (type changes, name remains the same), and then recreating the constraints is fairly elegant.

    Is the goal to ultimately drop the GUID columns? If so, you won’t actually reclaim the space unless the tables are copied or rebuilt, so maybe the following adjustment:

    …
    4.Script the data change “update table x, set NewPrimaryKey = y where OldPrimaryKey = z
    5.Drop the original primarykey to ‘oldprimarykey’
    6.Rename the ‘NewPrimaryKey’ column ‘PrimaryKey’
    7.Script back all the indexes and fkeys (building clustered indexes “rebuilds” tables)
    8.For all tables that don’t have clustered indexes, do something to make sure they get rebuilt and their space is reclaimed (such build and then drop a clustered index)

    Needless to say, test it on a dev box before running on Production!

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

Sidebar

Related Questions

I have two tables in my db that have millions of rows now, the
I have a postgresql DB with > 3 million rows in two tables. Something
I have two tables that get joined regularly. Table One is about 1 Million
I have two tables viz. Total_Data and Distinct_S1 . Total_Data has 3.5 million rows.
I have two tables, activities and activity_tours . activities hasMany activity_tours and are related
I have a data structure that looks like this: Model Place primary key id
I've got about 100 million rows that I'm moving in SSIS 2008 via a
i have two tables that are joined on a field rowid i need to
I have two somewhat big (4+ million records) tables with identical structure, and they
I have two tables TABLE A and TABLE B. TABLE A contain 1 million

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.