当前位置:网站首页>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;边栏推荐
- pwm转0-5V/0-10V/1-5V线性信号变送器
- Material dynamic self illumination
- 目前股票开户安全吗?可以直接网上开户吗
- 打造一个 API 快速开发平台,牛逼!
- PostgreSQL learning (based on rookie course)
- BFD原理与配置
- Uncover the practice of Baidu intelligent test in the field of automatic test execution
- 分页sql(rownum、row_number、dense_rank、rank)
- MySQL的json 数组操作 json_array_append、json_array_insert
- Unity C basic review 27 - delegation example (p448)
猜你喜欢

GWD:基于高斯Wasserstein距离的旋转目标检测 | ICML 2021

Construction and application of medical field Atlas of dingxiangyuan

我 35 岁,可以转行当程序员吗?

Wechat official account - menu

About sql+nosql: newsql database

Review of digital image processing

Flink SQL任务TaskManager内存设置

深度学习遥感数据集

ROS notes (10) - Launch file startup

明德扬XILINX-K7-325T/410T核心板数据手册
随机推荐
bash汇总线上日志
swift JSONSerialization
render后续来了,封装一个表单往表格中添加数据
Symfony framework security component firewall configuration
雷达天线简介
Lumiprobe 活性染料丨氨基染料:花青5胺
高分三号卫星(GF-3)简介
中序和后序遍历构建二叉树[递归划分区间与回溯拼接子树+中后序和中前序的相似与不同]
Informatics Olympiad all in one 1000: introductory test questions
MCS: multivariate random variable - discrete random variable
Hi, you have a code review strategy to check
Sofaregistry source code | data synchronization module analysis
Hi,你有一份Code Review攻略待查收
如临现场的视觉感染力,NBA决赛直播还能这样看?
SOFARegistry 源码|数据同步模块解析
遥感典型任务分析
MySQL的json 数组操作 json_array_append、json_array_insert
MCS:离散随机变量——Binomial分布
PWM to 0-5v/0-10v/1-5v linear signal transmitter
pwm转0-5V/0-10V/1-5V线性信号变送器