当前位置:网站首页>Mysql database design suggestions

Mysql database design suggestions

2022-06-25 19:09:00 Daiyuanpei

【 mandatory 】 The name of the database must be controlled in 32 Within characters , It consists of English characters and numbers . It is forbidden to use Chinese .

【 mandatory 】 The character set must be explicitly specified when creating the database , And the character set can only be utf8 perhaps gbk.

【 mandatory 】 The table name must be controlled within 32 Within characters . System reserved words and special characters cannot be used , Only letters can be used 、 Numbers and underscores .

【 mandatory 】 Column names must be controlled within 32 Within characters . System reserved words and special characters cannot be used , Only letters can be used 、 Numbers and underscores .

【 mandatory 】 The character set must be explicitly specified when creating a table , And the character set must be the same as the database character set ,utf8 perhaps gbk.

【 mandatory 】 The table storage engine type must be explicitly specified when creating a table , By default InnoDB. If necessary MyISAM And other engines , The unified platform cannot support .

【 mandatory 】InnoDB The table must have a primary key , The primary key must be self incrementing (auto_increment attribute )BIGINT type . The primary key column cannot be updated .

【 mandatory 】 All fields in the table must be NOT NULL attribute , Business can be defined as needed DEFAULT value .

【 mandatory 】 Fields and tables must have COMMENT.

【 mandatory 】 Field names in the table cannot use keywords

【 mandatory 】BLOB/TEXT Do not have default values

【 mandatory 】 Partitioned tables are not allowed .

【 mandatory 】 No use SELECT * Take all fields

【 mandatory 】INSERT You need to specify the field name to be inserted

【 mandatory 】 Triggers are not supported (Triger)

【 mandatory 】 Stored procedures are not supported (Procedure)

【 mandatory 】 Foreign key not supported (Foreign Key)

【 mandatory 】 Function not supported (Function)

【 mandatory 】 Views are not supported (Views)

【 mandatory 】 Events are not supported (Event)

【 mandatory 】DML Statement and DDL Separate the bill of lading

【 mandatory 】DML SQL The online order must be modified every time 1500 Row data select sleep(1)

【 mandatory 】drop The statement must have IF EXISTS, And one drop Statement can delete only one table

【 Strongly recommended 】 Table self increasing critical value inspection

【 Strongly recommended 】 Table name | Field names can only be lowercase

【 Strongly recommended 】 It is not recommended to use ENUM and SET.

【 Strongly recommended 】VARCHAR And CHAR The choice of : With UTF8 or GBK For example ,VARCHAR(200) contrast CHAR(200), On storage InnoDB Has been to CHAR(200) Fields are treated as variable length fields , There is no difference between the two . But for example, we store 32 Of length md5 value , You should use CHAR(32), Because although in InnoDB The storage layer is similar to VARCHAR(32) There is no difference , But use CHAR(32) It is helpful to convey the information that this is a regular field .

【 Strongly recommended 】BLOB,TEXT,MEDIUMTEXT,LONGTEXT It is not recommended to use .

【 Strongly recommended 】 Large tables with active business must have the creation time field of row data create_time And last update time fields update_time

【 Strongly recommended 】 The only key is “uk_” start , The general index is “idx_” start , All in lowercase , By table name / The name or abbreviation of the field is used as the suffix .

【 Strongly recommended 】InnoDB and MyISAM Storage engine table , Index type must be BTREE.

【 Strongly recommended 】 The length of each index record in a single index cannot exceed 64KB

【 Strongly recommended 】 The number of indexes on a single table cannot exceed 7 individual

【 Strongly recommended 】sql where The condition must have an index

【 Strongly recommended 】JOIN Table does not recommend more than 3 individual

【 Mandatory advice 】 It is strongly not recommended that sql Statement used %S% perhaps %S Fuzzy query

Suggest 】 The state of being less selective in a business status、 type type Etc. are recommended tinytint perhaps smallint type

Suggest 】 In business IP Unsigned integers are recommended for address fields int(10) UNSIGNED type

【 Suggest 】datetime Recommended int replace

原网站

版权声明
本文为[Daiyuanpei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190523357644.html

随机推荐