tags:

views:

34

answers:

2

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

Please advise.

TIA.

+1  A: 

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.

dcp
+1  A: 

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?

Ishtar
Thank you, now, where or how, would I find what is and is not acceptable? ie, How did you know that? Is there an internet based reference source for that? (I'm lacking the vernacular to find it!)
Brandon Bertelsen
Those operators are just basic SQL, they are explained in any book or tutorial about SQL. I don't know any reference or list... You can use `_`. Why would you need another symbol?
Ishtar
Basic SQL, yes, but there must be a link or a word that I could search for in the documentation that would land me on a page that describes this.
Brandon Bertelsen
The word your want is "syntax." For instance, here's a link to the syntax of the MySQL 5.0 SELECT statement: http://dev.mysql.com/doc/refman/5.0/en/select.html. In there, you will eventually run across how to form fully qualified column names, included database and table. In this case, though, I agree that it's basic SQL that comes pretty early in most, though maybe not all, SQL books -- especially when discussing joins where it becomes very useful or even required.
lilbyrdie