Jump to content

Redefine Relational Tables


mcfmullen

Recommended Posts

Okay, so I messed up big time.

 

I have a database made up of these tables:

Animals - ID, Name, Photo

Themes - ID, Theme, Comment

AnimalsThemes - ID, Name, Theme

 

I had the AnimalsMethods and AnimalsThemes relate Animals.Name to AnimalsThemes.Name and Themes.Theme to AnimalsThemes.Theme

 

Now I realize I should have been relating the IDs.

 

Is there any way I can do this, now that my tables have way too much information to start over?

 

I'm thinking that I should be importing the IDs relating to the names so that I can then delete the names column. Problem is, I don't know how to import the proper IDs to coincide with the proper names.

 

Here's hoping for a solution!

 

 

Link to comment
https://forums.phpfreaks.com/topic/220695-redefine-relational-tables/
Share on other sites

Well, then it should be pretty straightforward -- assuming each name has only a single ID, and vice versa.

 

Add new columns called animal_id, theme_id, etc. to the appropriate tables -- these will ultimately replace the name lookups.

 

Then simply issue an update to each table, and use a subquery to pull back the ID for each given name.

 

Then you can drop the other columns -- once you've updated your application code, foreign keys, etc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.