摘要: while循环 CREATE procedure addStudents() # 创建无参存储过程 BEGIN DECLARE i INT; # 申明变量 SET i = 0; # 变量赋值 WHILE i<5 DO # 结束循环的条件: 当i大于5时跳出while循环 INSERT INTO st 阅读全文
posted @ 2021-07-11 23:57 胡勇健 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 创建语法 create function 函数名(参数列表) returns 返回类型 begin 函数体 end 实例 create function getCount() returns int begin declare c int default 0; select count(*) int 阅读全文
posted @ 2021-07-11 23:09 胡勇健 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 含义 一组已经编译好的sql语句集合。 作用 1 提高代码重用性 2 简化操作 3 减少编译次数,和数据库链接次数,提高效率 创建语法 create procedure 存储过程名(参数列表) begin 存储过程 end; 实例 创建 create procedure getStudent(in 阅读全文
posted @ 2021-07-11 22:15 胡勇健 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 系统变量 查看系统变量 show variables show global variables show session variables show [global|session] variables like '%char%'; 查看指定系统变量 select @@global|[sessi 阅读全文
posted @ 2021-07-11 20:23 胡勇健 阅读(47) 评论(0) 推荐(0) 编辑
摘要: mysql版本 8.0.25 常用存储引擎 innodb (支持事务) Myisam (不支持事务) Meory (不支持事务) 查看表存储引擎 show create table school; show table status from school_info; show table stat 阅读全文
posted @ 2021-07-11 18:47 胡勇健 阅读(41) 评论(0) 推荐(0) 编辑
摘要: 创建数据库 create database if not exists books; 删除数据库 drop database if exists books; 显示所有数据库 show databases; 显示数据库所有表 show tables; 创建数据表 DROP TABLE IF EXIS 阅读全文
posted @ 2021-07-11 14:54 胡勇健 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 语法 delete from 表名 where 筛选条件 实例 delete from student where `id`= 7; 语法 truncate table 表名 实例 truncate table student; 阅读全文
posted @ 2021-07-11 14:12 胡勇健 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 语法 update 表名 set 列=值,列=值... where 筛选条件 实例 update student set `age`=32 where `id`=10; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Wa 阅读全文
posted @ 2021-07-11 14:00 胡勇健 阅读(1497) 评论(0) 推荐(0) 编辑
摘要: 语法1 insert into 表名(列名,...) values(值1,...); 实例 insert into student(`name`,`sex`,`age`,`class_id`,`status`) values('胡勇健','男',28,1,1); Query OK, 1 row af 阅读全文
posted @ 2021-07-11 13:41 胡勇健 阅读(701) 评论(0) 推荐(0) 编辑
摘要: 语法 select 列 from 表 【join type] join on 连接条件 where 筛选条件 group by 分组字段 having 分组后筛选 order by 排序字段 limit offset, size; 分页实例 select * from student limit 0 阅读全文
posted @ 2021-07-11 13:13 胡勇健 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 实例 SELECT * FROM student WHERE class_id IN ( SELECT id FROM class WHERE id = 2 ); + + + + + + + | id | name | sex | age | class_id | status | + + + + 阅读全文
posted @ 2021-07-11 12:36 胡勇健 阅读(31) 评论(0) 推荐(0) 编辑