imgrooot 1 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 post Share on other sites
Jacques1 629 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 post Share on other sites
Solution imgrooot 1 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 post Share on other sites
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.