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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:50:34+00:00 2026-05-17T16:50:34+00:00

I need to add a auto-inc surrogate key to three tables in my data

  • 0

I need to add a auto-inc surrogate key to three tables in my data warehouse:

Note: These are not the real table names

JakMaster (JakMasterId, Date) (PK) Note: JakMasterId is varchar(60)

JakToRoad (JakMasterId, Date) (FK)

JakToBig (JakMasterId, Date) (FK)

What steps should I take to add a surrogate key to these three tables so that the new keys reference each other correctly?

Thanks!

  • 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-17T16:50:34+00:00Added an answer on May 17, 2026 at 4:50 pm

    I’m assuming you are wanting to replace JakMasterId with an auto-increment field so the other two tables don’t need a varchar(60) field and to improve query times, but that you are keeping JakMasterId as information.

    -- set database single-user
    
    -- drop foreign keys
    
    create table NewMaster (ID int identity(1, 1), JakMasterId, Date))
    insert NewMaster(JakMasterId, Date) select JakMasterId, Date from JakMaster
    drop table JakMaster
    sp_rename 'NewMaster', 'JakMaster'
    
    alter table JakToRoad add MasterId int
    alter table JakToBig add MasterId int
    
    update JakToRoad set MasterId = JakMaster.ID
    from JakToRoad
    inner join JakMaster on JakMaster.JakMasterId = JakToRoad.JakMasterId
    
    update JakToBig set MasterId = JakMaster.ID
    from JakToBig 
    inner join JakMaster on JakMaster.JakMasterId = JakToBig .JakMasterId
    
    alter table JakToRoad drop column JakMasterId
    alter table JakToBig drop column JakMasterId
    
    
    alter table JakToRoad add constraint FK_JTRtoJM foreign key (MasterId) references JakMaster (ID)
    alter table JakToBig add constraint FK_JTBtoJM foreign key (MasterId) references JakMaster (ID)
    
    -- reset database to multi-user
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add an auto row at the end of the data table
I need to add a primary key to a set of tables in a
I need to add an auto increment id to an already existing table. I
I need add Auto complete on apex Tabular Form. there is a column as
I need to add an auto generated auto-increment id to a query results. For
I am building some auto-complete functionality using compass and I need to add an
I have table that doesn't need a specific field to be the primary key.
I need add a new user group for mediawiki. The new group has more
I can't access a element with its href. Like this example, i need add
Hї! I have wrote test for my application. I need add item to database

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.