MySql 笔记

drop database if exists school;

create database school default charset utf8;

-- 切换到数据库school

use school;

-- 创建学生表

drop table if exists tb_student;

create table tb_student

(

stuid int not null comment '学号',

stuname varchar(20) not null comment '姓名',

stusex bit default 1 comment '性别',

stubirth date comment '生日',

primary key (stuid)

);

alter table tb_student add column stuaddr varchar(255);

alter table tb_student change column stuaddr stuaddr varchar(511);

-- alter table tb_student drop column stuaddr;

insert into tb_student values(1003, '张三丰',1,'1982-2-2','湖北十堰');

insert into tb_student values(1004, '张二丰',1,'1982-2-2','湖北十堰');

insert into tb_student values(1005, '张一丰',1,'1982-2-2','湖北十堰');

insert into tb_student (stuid,stuname,stusex) values (1006,'素素',0);

insert into tb_student (stuid,stuname,stusex)

values

(1007,'杨逍',1),

(1008,'谢逊',1),

(1009,'杨不悔',0);

-- 截断表

-- truncate table tb_student--

-- 删除学生delete

delete from tb_student where stuid=1003;

--这是因为 MySql 运行在 safe-updates模式下,该模式会导致非主键条件下无法执行update或者delete命令,执行如下命令:

set sql_safe_updates=0;

delete from tb_student where stusex=0;

相关推荐
鄭郑30 分钟前
STM32学习笔记--I2C封装与OLED(2026.2.1)
笔记·stm32·学习
踩坑小念1 小时前
秒杀场景下如何处理redis扣除状态不一致问题
数据库·redis·分布式·缓存·秒杀
萧曵 丶1 小时前
MySQL 语句书写顺序与执行顺序对比速记表
数据库·mysql
酒鼎2 小时前
学习笔记(4)HTML5新特性(第3章)- WebSocket
笔记·学习·html5
Wiktok2 小时前
MySQL的常用数据类型
数据库·mysql
-Springer-2 小时前
STM32 学习 —— 个人学习笔记2-2(新建工程)
笔记·stm32·学习
tb_first2 小时前
万字超详细苍穹外卖学习笔记4
java·spring boot·笔记·学习·spring·mybatis
日更嵌入式的打工仔2 小时前
C内存布局
笔记
曹牧2 小时前
Oracle 表闪回(Flashback Table)
数据库·oracle
J_liaty2 小时前
Redis 超详细入门教程:从零基础到实战精通
数据库·redis·缓存