当前位置:网站首页>Mysql database naming conventions PDF
Mysql database naming conventions PDF
2022-06-29 15:24:00 【Code farmer Programming Advanced notes】
One 、 Database involves character specification
use 26 English letters ( Case sensitive ) and 0-9 These ten natural numbers , Underline '_' form , common 37 Characters . No other characters can appear ( Except for notes ). matters needing attention : 1) None of the above names should exceed 30 System limit of characters . The length of variable names is limited to 29( No Include identification characters @).
2) Data objects 、 Variables are named in English characters , Chinese naming is prohibited . Never be right Leave a space between the characters of the image name . 3) Be careful with reserved words , Make sure your field name doesn't contain any reserved words 、 Database system or common access Methods the conflict , When the table name or field name or even the database name conflicts with the reserved word , stay sql It can be used in the statement apostrophe (`) Cover up .
4) Keep field names and types consistent , When you name a field and assign a data type to it Be sure to ensure consistency . If the data type is an integer in a table , In another table, you should also make sure that integer .
Two 、 Database naming rules
The database name is composed of lowercase English and underscores (weixin+_jd_com). such as : weixin_jd_com im_jd_com The backup database name is composed of the official database name and the backup time , Such as : dbname_20150206
3、 ... and 、 Database table naming conventions
The data table name is composed of lowercase English and underscore ( Project name + Table information ) such as : oa_user oa_workflow_steps The backup data table name is composed of the formal table name and the backup time , Such as : oa_user_20150206
oa_workflow_step_20150206Four 、 Field naming conventions
Field names are done using word combinations , Initial lowercase , Use... Between words “_” Separate , It is better to prefix the table name .
Such as oa_user Table fields : user_id user_name The associated fields between tables should be named uniformly
5、 ... and 、 Index naming conventions
Index name is idx_ Name _ Table name abbreviation , The unique index name is uniq_ Name _ Table name abbreviation , The table name is And the associated field name if too long , You can take the table name 、 Before the associated field name 5 Letters , If table name 、 Turn off The associated field is a combination of multiple words , You can take the previous word , Add the first letter of other subsequent words Paragraph name
Such as the general index :idx_user_name_oa unique index uqidx_ user_name_oa
6、 ... and 、 Field type specification
The rules : Use as little storage space as possible to store the data of a field . For example, it can be used int The don't have char perhaps varchar It works varchar(20) The don't have varchar(255) The timestamp field should be int type
7、 ... and 、 Operation specification
If there are no remarks , Then the first one in the table id Fields must be primary keys and grow automatically ; If there are no remarks , Then use UNSIGNED attribute ; If there are no remarks , All fields are set NOT NULL, And set the default value ; All numeric type fields , Must set a default value , And set it as 0; in the light of varchar Type field handler , Please verify user input , Don't exceed its preset length ; When creating a table, write the Chinese name of the field and attribute comments in the data dictionary into the comments of the data table (“PK、 Automatically growth ” Do not write );
If not stated , When building a watch, we will use innodb engine ;. Try to use lots of SQL sentence , Reduce the number of interactions with the database Submit online table creation and table modification requirements , All... Involved must be specified SQL sentence ( Include INSERT、DELETE、UPDATE), Easy DBA Review and optimize .
8、 ... and 、 Other design skills
1) Avoid using stored procedures 、 trigger 、 View 、 Custom functions, etc , These advanced features have performance problems , And unknown BUG More . Putting the business logic into the database will result in DDL、SCALE OUT、SHARDING When it becomes more difficult . 2) Partition table has strict requirements for partition keys ; Partition table after the table becomes larger , perform DDL、SHARDING、 Single table recovery Waiting becomes more difficult . Therefore, the use of partitioned tables is prohibited , It is also recommended that the business side manually SHARDING.
3) Use common English ( Or any other language ) Don't use phonetic acronyms 4) Large fields 、 Fields with low access frequency are split into separate tables to store , Separate hot and cold data , advantageous to Make efficient use of cache , Prevent reading useless cold data , Fewer disks IO, At the same time, ensure that the thermal data is resident in the memory Improve cache 5) Prohibited super Application account with permission does not exist , Safety first .super Permissions can lead to read only invalid , It causes many strange problems and is difficult to track .6) Not in MySQL Store business logic in the database , Databases are stateful services , Changes are complex and Slow speed , If you put the business logic into the database , It will limit the rapid development of the business . It is suggested that the business logic Edit in advance , Put it in the front-end or middle logical layer , And take the database as the storage layer , Realize the separation of logic and storage .
attach : Table building example
CREATE TABLE `weixin_test` (
`id` int(20) unsigned NOT NULL AUTO_INCREMENT,
`staff_id` int(11) NOT NULL COMMENT ' The operator id',
`staff_name` varchar(50) NOT NULL COMMENT ' Name of personnel ',
`url` varchar(200) NOT NULL COMMENT ' Operation path ',
`method` varchar(10) NOT NULL COMMENT ' Mode of operation ',
`params` varchar(10) NOT NULL COMMENT ' Operating parameters ',
`ip` varchar(20) NOT NULL COMMENT 'ip',
`time` int(11) NOT NULL COMMENT ' Operating time ',
PRIMARY KEY (`id`),
KEY `idx_staff_id_ct` (`staff_id `)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;边栏推荐
- Solution to the problem that the assembly drawing cannot be recognized after the storage position of SolidWorks part drawing is changed
- Paging SQL (rownum, row_number, deny_rank, rank)
- 中序和后序遍历构建二叉树[递归划分区间与回溯拼接子树+中后序和中前序的相似与不同]
- 动态监听DOM元素高度变化
- ROS notes (10) - Launch file startup
- Intelligent diagnosis of Alzheimer's disease
- Lumiprobe 脱氧核糖核酸丨磷酸盐 CPG 1000 固体载体
- MCS: discrete random variable Pascal Distribution
- 分页sql(rownum、row_number、dense_rank、rank)
- BFD principle and configuration
猜你喜欢

揭秘百度智能测试在测试自动执行领域实践

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

MCS: multivariate random variable polynomial distribution

深度学习遥感数据集

MCS: discrete random variable - binomial distribution

Building SQL statements in Excel
![Abnormal logic reasoning problem of Huawei software test written test [2] Huawei hot interview problem](/img/f0/5c2504d51532dcda0ac115f3703384.gif)
Abnormal logic reasoning problem of Huawei software test written test [2] Huawei hot interview problem

Hi, you have a code review strategy to check

Sofaregistry source code | data synchronization module analysis

Informatics Olympiad all in one 2061: trapezoidal area
随机推荐
MCS: discrete random variable Poisson distribution
js获取上个月第一天以及本月的最后一天
这是少了什么依赖嘛?FlinkSql打包运行的时候报错,但是本地idea跑的时候是没问题的,求解,谢
Classe d'outils commune de fichier, application liée au flux (enregistrement)
Lumiprobe reactive dye miscellaneous dye: BDP FL ceramide
MySQL为什么选择B+树存储索引
Pytorch two-dimensional multi-channel convolution operation method
Material dynamic self illumination
雷达相关内容简介
MCS: multivariate random variable - discrete random variable
Unity C# 基础复习28——带返回的委托(P449)
PyTorch 二维多通道卷积运算方式
卷积神经网络中各层的作用
MySQL开发规范.pdf
Get the width of text component content
Lumiprobe deoxyribonucleic acid phosphate CpG 1000 solid carrier
Lumiprobe 活性染料丨杂染料:BDP FL 神经酰胺
Scroll,你玩明白了嘛?
中序和后序遍历构建二叉树[递归划分区间与回溯拼接子树+中后序和中前序的相似与不同]
Basic use of text preprocessing library Spacy (quick start)