Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL column name standards / conventions [closed]

Tags:

I'm looking for document (suggestions) with column name standards or conventions for MySQL. Can anybody suggest any?

like image 664
chubbyk Avatar asked Mar 16 '11 12:03

chubbyk


People also ask

What is naming convention in MySQL?

By default, MySQL encloses column names and table names in quotation marks. Table names can use any character that is allowed in a file name except for a period or a forward slash. Table names must be 32 characters or less because SAS does not truncate a longer name.

What type of standards need to followed in naming table columns?

The generic standards for the column naming are as follows: Column names must contain only A to Z, 0 to 9, and underscore (_) characters. Column names can contain multiple underscores. The column name must not be very generic.

Which characters are not allowed in MySQL?

ASCII NUL (U+0000) and supplementary characters (U+10000 and higher) are not permitted in quoted or unquoted identifiers. Identifiers may begin with a digit but unless quoted may not consist solely of digits. Database, table, and column names cannot end with space characters.

Should SQL column names be capitalized?

SQL commands, datatypes, and constraints (e.g. DEFAULT , PRIMARY KEY , AUTO INCREMENT , etc.) should be in ALLCAPS . It is legal to write commands in lowercase, but this often leads to subtle bugs with lowercase attribute/column names, so we expect you to use the ALLCAPS convention for any commands or datatypes.


1 Answers

There's nothing "standard" in this space I'm aware of, unlike say Sun's old Java conventions. Anything you adopt will be personal/company preference.

That said, I do like prefix conventions:

  • t_ for table
  • v_ for view
  • idx_ for index
  • tx_ for text field
  • dt_ for date field
  • n_ for numeric field
  • id_ for identify field
  • nm_ for something that's specifically a name
  • is_ for booleans, whether 0/1, yes/no or otherwise
  • fk_ as an optional foreign key identifer; you may prefer to stick with id_ though, to keep the field the same as its primary key counterpart, e.g. id_customer -> id_customer, rather than an fk_customer
like image 193
Brian Avatar answered Oct 10 '22 12:10

Brian