Detailed explanation of database specification

First, the database library name, table name, field name naming convention:

   1. Camel case notation: refer to the specification for naming variable names in java, that is, if there is only one word, all lowercase; when there are multiple words, the first word is all lowercase, and all subsequent words are capitalized. . for example:

     userName,id,userPasswd,creatTime,updateTime,age等。

   2. Underline notation: multiple words are separated by underscores, all words are lowercase, within 32 characters, no reserved keywords are required, and all fields are not null . for example:

     user_name,id,user_passwd,create_time,update_time,age等。

Combining the above two naming conventions, I personally feel that the hump method is better. It feels beautiful to look at, highly readable, takes up less space, is easier to type, and is better for people who have used java. C/C++ and python are underscore, java and go are camel case. In fact, as long as people who have written java or go programs, basically think that the hump is more beautiful. Underscores are really hard to type. However, the underscore is already the norm for DBAs, and it is difficult to change it.

   3. Field specification.

      1) Non-negative value: unsigned

      2) Store IPV4: int unsigned

      3) Store floating-point values: decimal, do not use float and double

      4) Reasonable selection of integer range: tinyint, smallint, mediumint, int, bigint

      5) All fields have: not null modification, and set the default value

      6) Reasonable selection of time types: year, date, datetime, timestamp

      7) varchar(N) is as small as possible: N represents the number of characters, not the number of bytes

      8) Use as much as possible: text, blob, enum (replace with tinyint)

   4. Library table specification.

      1) Prohibit partition table;

      2) Reasonable sub-library sub-table;

      3) Separate hot and cold data;

      4) A hash table is recommended. The suffix of the table name is a decimal number, and the number must start from 0. The table by date and time must conform to the YYYY[MM][DD][HH] format, such as 2013071601. The year must be represented by 4 digits. For example, user_20110209 is distributed daily, user_201102 is distributed monthly;

      5) All tables require comments;

      6) It is forbidden to store large fields and large amounts of data (5000W)

 

 

Second, the global norms. Default storage engine, default character set

 

 

 

 

 

Third, the primary key specification. Each table must have a primary key, and it is recommended to use self-incrementing unsigned integer data.

 

Fourth, the index specification.

 

 

 

 

 

Five, SQL statement specification.

 

Second, the primary key specification.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325249281&siteId=291194637