Jump to content

Is it better to use to id or actual name when relating to another table in MySQL database?


imgrooot
Go to solution Solved by imgrooot,

Recommended Posts

Say I have 2 tables.

 

Table 1: Type(type_id, type_name)

Table 2: Records(record_id, record_name, record_type)

 

Under the "record_type" column, is it better to use type_id(eg. 10) or type_name(eg. Clothing & Watches)?  If the answer is use the name, is it better to use the original name(Clothing & Watches) or a slug name(clothing-watches)?

Link to comment
Share on other sites

So you're talking about a foreign key used to join the two tables?

 

Then the ID is better, because it's stable and efficient. Names change, which means the database has to keep the tables synchronized. And names are long, which means it's relatively expensive to compare them.

 

Numeric IDs, on the other hand, are unlikely to ever change, and they have a fixed length.

  • Like 2
Link to comment
Share on other sites

  • Solution

So you're talking about a foreign key used to join the two tables?

 

Then the ID is better, because it's stable and efficient. Names change, which means the database has to keep the tables synchronized. And names are long, which means it's relatively expensive to compare them.

 

Numeric IDs, on the other hand, are unlikely to ever change, and they have a fixed length.

 

Got ya. Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.