I have read may questions and answers as to simplicity of a mysql DB and good practice.
I have a mysql DB, with a 'clients" table. Each client added has an email, which is unique as to emails. Using C++ Builder there are problems adding records caused by the id field auto incremented - forcing to manually increment the id during adding new rows using DBEXPRESS.
Why not skip the auto incremented id ? Will it be good practice to have a table without (auto incremented) id, and have the email as unique key ? That would solve the DBEXPRESS problem.
No: Don't use email as the primary key. There a few reasons why:
id
. Conforming to industry standards is good practice.Conceptually, yes, it is a good idea to not generate artificial unique keys (or at least, limit those instances). And e-mail
serves that natural unique key purpose.
However, one thing I would be worried about is performance. Having an integer as an id is pretty convenient when doing queries and it is a lot faster to search in those than long strings... It does not matter if you simply retrieve a user from the database using the e-mail address. But it matters if you have complex queries with multiple joins.
Also, if you store information about clients in multiple tables, the foreign keys to the other table will be the e-mail address. That means that you store the e-mail address multiple times, which will make it a lot harder to keep everything updated if a client decides to change his e-mail someday.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With