First, the basic norms
- You must use the InnoDB storage engine
- You must use the UTF8 character set
- Data table, data fields must be added in Chinese comments
Second, the design code
- The library name, table name, field name must be lowercase, preferably not camel, using "_" to differentiate, such as user_name
- Library name, table name, field name should not be too long, control within 12 character range
- Each table is set to a self-increment primary key, and the primary key should not be modified. (Avoid page splitting, reduce table fragmentation to improve space and memory usage)
- can use int type to replace varchar, char with int type as far as possible
- No more than 20 fields in a single table field
- Define a not NULL for each field and provide a default value
- Use varchar (20) to save the phone number, as it may involve an area code or a country code that may appear + + ()
III. SQL specification
- SQL as simple as possible
- Avoid using SELECT *
- or overwrite as in or union
- Avoid%xxx rewriting to xxx%
- INSERT into A values (AA,VV,CC), to indicate which columns are inserted, to avoid creating an accident due to inconsistent sequence
- Prohibit the use of functions on the where field, to be used after a condition. SELECT uid from T_user WHERE day>= unix_timestamp (' 2017-02-15 00:00:00 ')
MySQL Design specification