当前位置: 首页 > news >正文

MySQL学习笔记-部分实例datagrip源码-10-21

show tables;
create table user(id int primary key auto_increment,name varchar(10) not null unique,age int check(age>0 and age<=120),status char(1) default '1',gender char(1)
) comment '用户表';
-- 添加数据
insert into user(name, age, status, gender) values('张三', 20, '1', '1'), ('李四', 20, '0', '1');
insert into user(name, age, status, gender) values('王五', 20, '1', '0');insert into user(name, age, status, gender) values(null, 20, '1', '0');
insert into user(name, age, status, gender) values('王五', 20, '1', '0');
insert into user(name, age, status, gender) values('小七', 80, '1', '0');
insert into user(name, age, status, gender) values('小九', 121, '1', '0');
insert into user(name, age, gender) values('小九', 120,'0');create table dept(
id int auto_increment comment 'Io' primary key,
name varchar(50)not null comment'部门名称'
)comment'部门表';
INSERT INTo dept (id, name) VALUES(1,'研发部'),(2,'市场部'),(3,'财务部'),(4,'销售部'),(5,'总经办');
create table emp(id        int auto_increment comment 'ID' primary key,name      varchar(50) not null comment '姓名',age       int comment '年龄',job       varchar(20) comment '职位',salary    int comment '薪资',entrydate date comment '入职时间',managerid int comment '直属领导ID',dept_id   int comment '部门ID'
)comment'员工表';INSERT INTo emp (id, name, age, job,salary, entrydate, managerid, dept_id) VALUES
(1,'金庸',66,'总裁',20000,'2080-01-01',null,5),
(2,'张无忌',20,'项日经理',12500,'2005-12-05',1,1),
(3,'杨道',33,'开发',8400,'2000-11-03',2,1),
(4,'韦一笑',48,'开发',11000,'2002-02-05',2,1),
(5,'常遇春',43,'开发',10500,'2004-09-07',3,1),
(6,'小昭',18,'程序员鼓励师',6600,'2004-10-12',2,1);
-- 添加外键
alter table emp add constraint fk_emp_dept_id foreign key (dept_id) references dept(id);
-- 删除外键
alter table emp drop foreign key fk_emp_dept_id;create table account(
id int auto_increment primary key comment'主键ID',name varchar(10)comment'姓名',money int comment'余额comment"账户表');
insert into account(id, name, money)VALUES (nuLl,'张三',2000),(null,'李四',2000);
select @@autocommit;
set @@autocommit = 1 ;
update account set money = 2000 where name = '张三'or name = '李四';
-- 转账操作(张三给李四转账1000)
-- 1.查询张三账户余颜
select * from account where name ='张三';
-- 2.将张三账户余额-1000
update account set money=money-1000 where name ='张三';
程序执行报错 ......
-- 3.将李四账户余额+1000
update account set money = money + 1000 where name ='李四';
-- 事务提交
commit;
-- 事务回滚
rollback;
-- 方式二
-- 转账操作(张三给李四转账1000)
start transaction;
-- 1.查询张三账户余颜
select * from account where name ='张三';
-- 2.将张三账户余额-1000
update account set money=money-1000 where name ='张三';
程序执行报错 ......
-- 3.将李四账户余额+1000
update account set money = money + 1000 where name ='李四';
-- 事务提交
commit;
-- 事务回滚
rollback;
-- 查看事务隔离级别
select @@transaction_isolation;
-- 设置事务隔离级别
set session transaction isolation level read uncommitted;
-- 设置事务默认级别
set session transaction isolation level repeatable read ;
-- 1.事务简介
-- 事务是一组操作的集合,这组操作,要么全部执行成功,要么全部执行失败。
-- 2.事务操作
-- START TRANSACTION;--开启事务
-- COMMIT/ROLLBACK;--提交/回滚事务
-- 3.事务四大特性
-- 原子性( Atomicity )、一致性( Consistency)、隔离性( Isolation)、持久性( Durability)
-- 4.并发事务问题
-- 赃读、不可重复读、幻读
-- 5.事务隔离级别
-- READ UNCOMMITTED 、READ COMMITTED、 REPEATABLE READ、SERIALIZABLE

 

http://www.hskmm.com/?act=detail&tid=37813

相关文章:

  • sudo apt install cmake ERROR: ld.so: object /home/ma-user/anaconda3/envs/xxxx/lib/python3.9/site-pa
  • 2025年10月中国引流营销公司推荐榜:五强对比评测
  • 示波器探头衰减怎么判断?3 种方法 + 常见问题,新手也能学会​
  • 制造业数字化效率低到哭?AI 低代码自动生接口、拼流程,JNPF 级平台让集成效率提 500% - 实践
  • WPF 和 Avalonia 开发者的 html css 前端指南 ComboBox 篇
  • ORA-01033 : ORACLE initialization or shutdown in progress
  • 2025年化工原料厂家推荐排行榜:双氧水/片碱/盐酸/磷酸/PAC/聚丙烯酰胺/消泡剂/阻垢剂等工业级化学品供应商精选
  • ESP32-BLE-NIMBLE蓝牙透传DEMO
  • 2025年10月深圳近视手术医生推荐榜:五强排行与选择要点
  • 2025年10月深圳近视手术医生推荐榜:朱少栋李伟力领衔对比
  • 数据库内部错误00600 故障处理
  • 2025年10月销毁公司推荐:森蓝领衔服务榜对比
  • 2025年危险品运输企业权威推荐榜:专业资质与安全口碑兼具的合规运输服务商精选
  • Docker镜像库配置
  • ref和reactive和.value
  • 2025年工作服厂家推荐排行榜,防静电/劳保/国网/餐厅/工厂/电工/防酸碱/电力/车间/航空/员工工作服,文化衫/t恤/polo衫/冲锋衣/t恤衫公司精选
  • 2025年10月淡化痘印产品推荐对比:从色素代谢到修护通路全解析
  • 2025年10月上海装修公司推荐榜:千州装饰等五家深度对比
  • 2025年10月上海装修公司对比榜:千州装饰等五强口碑解析
  • 2025年10月敏感肌美白面霜推荐榜:淡斑修护综合排名
  • 2025年10月色斑淡化产品对比榜:五款精华通路机制深度解析
  • 2025年10月医美项目后用什么产品评测榜:术后舒缓精华口碑对比
  • 题解:P4204 [NOI2006] 神奇口袋
  • 2025年超声波检测设备厂家权威推荐榜:相控阵/高频/水浸/液冷板/钎焊超声波检测系统,技术实力与选购指南深度解析
  • 一些c语言特殊用法
  • 2025年环氧板厂家推荐排行榜,环氧板加工,FR-4玻纤板,云母板,专业定制与优质材料供应商精选
  • 2025.10.24——1绿
  • 2025年精密弹簧厂家权威推荐榜单:压缩弹簧、拉伸弹簧、扭转弹簧、异形弹簧专业制造商综合评测与选购指南
  • PyQuokka框架存在Pickle反序列化远程代码执行漏洞
  • sql server查看所有表名以及注释