imgrooot Posted July 25, 2016 Share Posted July 25, 2016 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)? Quote Link to comment https://forums.phpfreaks.com/topic/301581-is-it-better-to-use-to-id-or-actual-name-when-relating-to-another-table-in-mysql-database/ Share on other sites More sharing options...
Jacques1 Posted July 25, 2016 Share Posted July 25, 2016 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. 2 Quote Link to comment https://forums.phpfreaks.com/topic/301581-is-it-better-to-use-to-id-or-actual-name-when-relating-to-another-table-in-mysql-database/#findComment-1534981 Share on other sites More sharing options...
Solution imgrooot Posted July 26, 2016 Author Solution Share Posted July 26, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301581-is-it-better-to-use-to-id-or-actual-name-when-relating-to-another-table-in-mysql-database/#findComment-1535092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.