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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:04:23+00:00 2026-06-12T00:04:23+00:00

I have two tables, both already populated with data, and with the following columns:

  • 0

I have two tables, both already populated with data, and with the following columns:

Table1
jobType char
jobDesc varchar

New_table
jobID int
jobType char

I want to replace Table1.jobType with a jobID column, such that Table1 will now reference to New_table using jobID. Any existing data in Table1.jobType must be “translated” to the appropriate jobID.

  • 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-12T00:04:24+00:00Added an answer on June 12, 2026 at 12:04 am

    The basic drill:

    • Start with the original job table

      create table dbo.job
      (
        id              int          not null identity(1,1) ,
        job_type        varchar(64)  not null ,
        job_description varchar(128) not null ,
      
        constraint job_PK primary key clustered (id) ,
      
      )
      
    • Create the new job type table (don’t forget to populate it)

      create table dbo.job_type
      (
        id   int         not null identity(1,1) ,
        name varchar(64) not null ,
      
        constraint job_type_PK   primary key clustered ( id   ) ,
        constraint job_type_AK01 unique nonclustered   ( name ) ,
      
      )
      
    • Alter the table dbo.job to add a new job_type_id column

      alter table dbo.job
      add job_type_id int null
      
    • Update the job table, mapping the value of job_type_id based on the [old] job_type column’s value.

      update dbo.job
      set job_type_id = jt.id
      from dbo.job      j
      join dbo.job_type jt on jt.name = j.job_type 
      
    • Alter the new column to make it non-nullable. This will fail until you’ve ensured that all rows have a non-null value for job_type_id:

      alter table dbo.job
      alter column job_type_id int not null
      
    • Add the new foreign key constraint needed

      alter table dbo.job
      add constraint job_AK01
      foreign key ( job_type_id )
      references dbo.job_type ( id )
      
    • The last and irrevocable step is to drop the old column. This will break any queries, stored procedures, etc. that reference this column…but you already did your homework in this department and have coordinated all necessary changes, right?

      alter table dbo.job drop column job_type
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables invoices and pending_payments both of which have the following rows
I have two tables in a SQLite DB, and both have the following fields:
I have two tables table1 = records, table2 = duplicates. Both tables contain a
I have two tables. Each one is populated with about 50K records. Both have
I have two tables (already created), say Person and Address with following schemas: create
i have two tables both are related with primary-foreign key ralation and i have
I have two tables. Both tables are editable and both tables should allways be
We have two tables in our application that both have a ShowOrder column. We
I have two tables, both named as say, Employee in two different schema HR
I have two tables: orders and orders_items. Both sharing the field orderID. I want

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.