LMSouq
database Open

Is there a naming convention for MySQL?

ST
StackOverflowNewbie
1 month ago
3 views
Problem Description
Here's how I do it: 1. Table names are lower case, use underscores to separate words, and are singular (e.g. `foo`, `foo_bar`, etc. 2. I generally (not always) have an auto increment PK. I use the following convention: `tablename_id` (e.g. `foo_id`, `foo_bar_id`, etc.). 3. When a table contains a column that is a foreign key, I just copy the column name of that key from whatever table it came from. For example, say table `foo_bar` has the FK `foo_id` (where `foo_id` is the PK of `foo`). 4. When defining FKs to enforce referential integrity, I use the following: `tablename_fk_columnname` (e.g. furthering example 3, it would be `foo_bar_foo_id`). Since this is a table name/column name combination, it is guaranteed to be unique within the database. 5. I order the columns like this: PKs, FKs, then the rest of columns alphabetically Is there a better, more standard way to do this?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base