当前位置:网站首页>【mysql篇-基础篇】通用语法2
【mysql篇-基础篇】通用语法2
2022-06-30 00:27:00 【小项~】

函数:
- 字符串函数
- 常用字符串函数:
- 演示:
A、concat:字符串拼接
select concat(‘hello’,‘world’);----> helloworld
B、lower:全部转小写
select lower(‘Hello’);---->hello
C、upper:全部转大写
select lower(‘hello’); ---->HELLO
D、lpad:左填充
select lpad(‘01’,5,‘-’);---->- - -01
E、rpad:右填充
select lpad(‘01’,5,‘-’);---->01- - -
F、trim:去除空格
select concat(’ hello world ');---->hello world
G、substring:截取子字符串(mysql的索引值从1开始)
select substring(‘Hello World’,1,5);---->Hello
- 数值函数
- 常见的数值函数:
- 演示:
A、ceil:向上取整(只要是小数位不是0,就会向上进一位)
select ceil(1.1);---->2
select ceil(1.5);---->2
B、floor:向下取整(向下取整,都会去掉小数点后面的数字)
select floor(1.1);---->1
select floor(1.9);---->1
C、mod:取模
select mod(7,4);---->3
D、rand:获取随机数(0-1之间)
select rand();
E、round:四舍五入
select round(1.544,2);---->1.54
- 日期函数
- 常见的日期函数:
- 流程函数
- 常见的流程函数:
约束:
- 概念:
约束是作用于表中字段上的规则,用于限制存储在表中的数据。
- 目的:
保证数据库中的数据的正确、有效性和完整性。
- 分类
- 注意:
- 约束是作用于表中字段上的,可以在创建表/修改表的时候添加约束。
- AUTO_INCREMENT修饰主键的自增长。
- 外键约束
- 概述:用来让两张表的数据之间建立连接,从而保证数据的一致性和完整性。
- 语法:
(1)CREATE TABLE 表名(
字段名 数据类型,
…
CONSTRAINT 外键名称 FOREIGN KEY (外键字段名) REFERENCES 主表(主表列名));
(2)ALTER TABLE 表名 ADD CONSTRAINT 外键名称 FOREIGN KEY(外键字段名) REFERENCES 主表(主表列名);
- 删除外键:
ALTER TABLE 表名 DROP FOREIGN KEY 外键名称;
- 外键删除更新行为
- 概念:添加外键后,删除父表数据时产生的约束行为。
- 行为列表:
- 语法:
ALTER TABLE 表名 ADD CONSTRAINT 外键名称 FOREIGN KEY(外键字段) REFERENCES 主表(主表字段名) ON UPDATE CASCADE ON DELETE CASCADE;
边栏推荐
- C MDI open subform to remove automatically generated menu bar
- 利用 CertBot 申请 Let’s Encrypt SSL 证书
- What does it mean to open an account online? In addition, is it safe to open an account online now?
- MySQL基础篇1
- Connection query of SQL Server database
- Botu V16 changes the model and firmware version of PLC
- Applying for let's encrypt SSL certificate with certbot
- 剑指 Offer II 037. 小行星碰撞
- EB-5 immigration in the United States reappears to be positive, and the reauthorization policy of the regional center is suspended
- TwinCAT 3 el7211 module controls Beifu servo
猜你喜欢

Introduction to reptiles: data capture of Betta barrage, with 11 introductory notes attached

Relevance - canonical correlation analysis

There is no web-based development for the reward platform. Which is suitable for native development or mixed development?
![[advanced C language] string and memory function (I)](/img/fa/5531253940d99f2646cb6964992e7c.png)
[advanced C language] string and memory function (I)

How to seamlessly transition from traditional microservice framework to service grid ASM

Mysql:sql overview and database system introduction | dark horse programmer

TwinCAT 3 EL7211模块控制倍福伺服

SOFARegistry 源码|数据同步模块解析

HDCP Paring

EB-5 immigration in the United States reappears to be positive, and the reauthorization policy of the regional center is suspended
随机推荐
mysql 死锁
Web APIs environment object - dark horse programmer
将日志文件存储至 RAM 以降低物理存储损耗
8 software engineering environment
Applying for let's encrypt SSL certificate with certbot
Finding a job in 2022 is the "last lesson" for graduates
Relevance - canonical correlation analysis
分布式任务调度 ElasticJob demo
Citation of Dissertation
[advanced C language] dynamic memory management
Use of shortcut keys for idea tools
MySQL advanced 1
There is no web-based development for the reward platform. Which is suitable for native development or mixed development?
MySQL基础篇1
Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!
Five key elements of the data center
Can't recognize the original appearance
股票网上开户及开户流程怎样?还有,在线开户安全么?
【UITableView】坑一:tableView:heightForHeaderInSection:方法不执行
Sofaregistry source code | data synchronization module analysis





