Brandon Bertelsen
Brandon Bertelsen

Reputation: 44648

MySQL Field and Table Name Conventions

Are there any naming conventions for tables/fields within MySQL? I have found a big list of "reserved words" but other than that are there any other concerns about naming?

For example, are field/table names like this acceptable:

p_name
p.name
p-name

Upvotes: 1

Views: 3762

Answers (2)

dcp
dcp

Reputation: 55444

I think the main thing is to just be consistent.

I prefer table names like these:

order
order_detail
customer
address
customer_address (links customer and address)

I use the same convention for column names (lower case, separate important words with an underscore).

This is the convention I've seen used most often across many different databases, but again, the main thing is to just pick a pattern and stick with it.

Upvotes: 2

Ishtar
Ishtar

Reputation: 11662

You can not use p.name or p-name as fields! p.name would mean field name from table p. p-name means subtract field name from field p.

Prefixes in a database can be useful if there are third party tables in the same database. For example, mantis prefixes (by default) all table names with mantis_ to prevent name collisions. I would not recommend this for fields, but that's a matter of taste, right?

Upvotes: 3

Related Questions