当前位置:网站首页>MySQL基础篇【命名规范】
MySQL基础篇【命名规范】
2022-07-30 05:51:00 【大脑不能为空】
一、MySQL在不同系统下的命名问题
1. Linux
- 数据库名与表名是严格区分大小写的;
- 表的别名是严格区分大小写的;
- 列名与列的别名在所有的情况下均是忽略大小写的;
- 变量名也是严格区分大小写的;
2. Windows
- 全部不区分大小写
二、推荐采用统一的书写规范
数据库名、表名、表别名、字段名、字段别名等都小写,定义数据库、表、列的时候全部采用小写字母加下划线的方式,不使用任何大写字母。
SQL 关键字、函数名、绑定变量等都大写
三、命名规则
- 数据库、表名不得超过30个字符,变量名限制为29个
- 必须只能包含 A–Z, a–z, 0–9, _共63个字符
- 数据库名、表名、字段名等对象名中间不要包含空格
- 同一个MySQL软件中,数据库不能同名;同一个库中,表不能重名;同一个表中,字段不能重名
- 必须保证你的字段没有和保留字、数据库系统或常用方法冲突。如果坚持使用,请在SQL语句中使用 `(着重号)引起来
- 保持字段名和类型的一致性,在命名字段并为其指定数据类型的时候一定要保证一致性。假如数据类型在一个表里是整数,那在另一个表里可就别变成字符型了
示例:
#以下两句是一样的,不区分大小写
show databases;
SHOW DATABASES;
#创建表格
#create table student info(...); #表名错误,因为表名有空格
create table student_info(...);
#其中order使用``飘号,因为order和系统关键字或系统函数名等预定义标识符重名了
CREATE TABLE `order`();
#起别名时,as都可以省略
select id as "编号", `name` as "姓名" from t_stu;
#如果字段别名中没有空格,那么可以省略""
select id as 编号, `name` as 姓名 from t_stu;
#错误,如果字段别名中有空格,那么不能省略""
select id as 编 号, `name` as 姓 名 from t_stu;
边栏推荐
猜你喜欢
向量叉乘的几何意义及其模的计算
Camera coordinate system, world coordinate system, pixel coordinate system conversion, and Fov conversion of OPENGLDEFocal Length and Opengl
What new materials are used in the large aircraft C919?
DHCP原理与配置
Go语学习笔记 - gorm使用 - 数据库配置、表新增 Web框架Gin(七)
LVM和磁盘配额
Polygon 3D(三维平面多边形)的法向量的计算(MeshLab默认的计算)
华为发布“十大发明”,包含计算、智能驾驶等新领域
图解关系数据库设计思想,这也太形象了
Is it possible to use the same port for UDP and TCP?
随机推荐
Ali two sides: List several tips for Api interface optimization
DHCP principle and configuration
uniapp中canvas与v-if更“配”
Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
redis实现分布式锁的原理
When does MySQL use table locks and when does it use row locks?
No, the Log4j vulnerability hasn't been fully fixed yet?
Redis download and installation
首届人工智能安全大赛正式启动
什么是微服务?
sql concat()函数
The usage of window.open(), js opens a new form
export , export default, import complete usage
The Society of Mind - Marvin Minsky
The newcomer deleted data by mistake, and the team leader skillfully used MySQL master-slave replication to delay the recovery of losses
从追赶到超越,国产软件大显身手
The Geometric Meaning of Vector Cross Product and the Calculation of Modulus
空间顶点到平面的距离计算的证明及其源码
开发常用工具软件
DNS domain name resolution services