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

  • Home
  • SEARCH
  • 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 6774455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:47:20+00:00 2026-05-26T15:47:20+00:00

I just finished some database changes and now I need to migrate the data

  • 0

I just finished some database changes and now I need to migrate the data to fit the new design.

We had a table of vehicles with a classification column. The classification column was a string someone typed into the field. It was not a foreign key column.

Now, I changed the design to allow a vehicle to have multiple classifications (yes, business rules allow this) and the classifications are moved to a lookup table. The classification column will be removed from the vehicle table, replaced with a M:M join table to enable the multiple categories per vehicle requirement. The classification table has been built using the unique values from the classification column in the vehicles table.

On to the question. How to I build the M:M table? What is the SQL to do this?

In my mind, the process would be: for each row in the vehicle table b) lookup the classification string in the new classification table c) insert the classification ID and the vehicle ID into the VehiclesClassifications table. Then, after checking the data, I’d manually remove the classification column from the vehicle table.

Thanks for any suggestions!

Edit 1 : I have the tables created. I’m just stumbling over the SQL statements.

  • 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-26T15:47:21+00:00Added an answer on May 26, 2026 at 3:47 pm

    How to I build the M:M table?

    Guessing at some data types, column names, etc.

    create table vehicle_classifications (
      vehicle_id integer not null references vehicles (vehicle_id),
      classification_id integer not null references classifications (classification_id),
      primary key (vehicle_id, classification_id)
    );
    

    Then something like

    insert into vehicle_classifications (vehicle_id, classification_id)
    select t1.vehicle_id, t2.classification_id
    from vehicles t1
    inner join classifications t2 on t1.classification = t2.classification
    

    Then, after checking the data, I’d manually remove the classification
    column from the vehicle table.

    Make sure you have foreign key constraints on the new join table before you do that.

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

Sidebar

Related Questions

I've just finished reading Domain Driven Design and I'm enchanted with some of the
I'm pretty new to android, and just finished setup my environment and reading some
I need to backup just some of the tables in my main database. The
I am setting up a rails app and I just finished making some unit
I just finished a small project where changes were required to a pre-compiled, but
I just finished using Linq to Sql to map our existing Database structure for
I'm new to computer coding and have just finished coding an app and tested
I'm learning about software engineering and design right now, and after reading some books
I just finished a Django app that I want to get some outside user
I've nearly finished rewriting (with some new features) my Symfony (left a bit bad

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.