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;

相关推荐
web151173602231 小时前
Redis--模糊查询--方法实例
数据库·redis·缓存
TT-Kun1 小时前
MySQL | 库操作
数据库·mysql
GreatSQL社区1 小时前
【GreatSQL优化器-15】index merge
数据库·oracle
东方芷兰2 小时前
算法笔记 04 —— 算法初步(下)
c++·笔记·算法
PengShuaiD52 小时前
【数据库维护】如何解决Clickhouse数据库Too many parts报错
数据库·clickhouse
TechNomad2 小时前
C++访问MySQL数据库
数据库·c++·mysql
数据的世界013 小时前
Deepin(Linux)安装MySQL指南
数据库·mysql
Jack魏3 小时前
Linux MySQL 8.0.29 忽略表名大小写配置
linux·mysql·mysql8·mysql常见问题
Warren984 小时前
Springboot中分析SQL性能的两种方式
java·spring boot·后端·sql·mysql·intellij-idea
左灯右行的爱情4 小时前
Redis-事务
数据库·redis·bootstrap