Toad World® Forums

Change Primary Key to Foreign Key

I reverse engineered a MySQL database, but there are no foreign keys imported.

What is the easiest way to change the primary keys to Foreign keys?

The only way I know is to create new foreign keys and delete the old ones, but I wonder if there’s a better way, especially as the field names are the same (e.g. UserID is the primary key in the Users table, UserID is a foreign key from Users in the Templates table)

Hi,

you have two better options:
a) Click Macros | All | Infer relationships and let the tool to “guess” relationships.
b) Draw new relationship between your tables. The latest version of TDM has the Automatic foreign keys mapping feature that allows you to map existing attribute to parent key attribute. See this:

http://toadworld.com/Blogs/tabid/67/EntryId/905/Automatic-Foreign-Keys-Mapping-in-Toad-Data-Modeler.aspx

Regards,

Vaclav