Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database name convention: DATETIME column

What is your naming convention for DATETIME columns (in my case, using MS SQL Server)

For a column that stores when the row was created CreatedDatetime makes sense, or LastModifiedDatetime.

But for a simple table, let's say one called Event, would you create columns called:

EventID,                 // Primary key EventDatetime,           // When the event is happening EventEnabled             // Is the event is on 

or

ID,                      // Primary key Datetime,                // When the event is happening Enabled                  // Is the event is on 

If you'd use neither convention: Please provide the column name you would use.

like image 449
Peter Bridger Avatar asked Sep 04 '09 14:09

Peter Bridger


People also ask

How do you name a column in a timestamp?

If you use TIMESTAMP then you don't have to specify a column name and SQL Server will create a column "TimeStamp" for you. But it is recommended to use "ROWVERSION" data type and in this case you have to specify the column name.

What is the naming convention of a column?

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. Avoid words such as term, multiplier, description, name, code, and so on.

How do you name a column in a database?

Database object names, particularly column names, should be a noun describing the field or object. Avoid using words that are just data types such as text or timestamp . The latter is particularly bad as it provides zero context. Underscores separate words.


1 Answers

I normally name DATETIME columns as ACTION_WORD_on: created_on, completed_on, etc.

The ACTION_WORD defines what the column represents, and the suffix (_on) indicates that the column represents time.

Other suffixes (or even prefixes) may be used to specify the data type (_at, _UTC, when_, etc).

Be descriptive. Be consistent.

like image 178
Steven Avatar answered Sep 24 '22 08:09

Steven