一、创建数据库
— 查看所有的数据库
show databases;
— 创建名为schoo的数据库
create database school default charset utf8mb4;
— 如果school数据库存在删除名为school的数据库
drop database if exists school;
— 切换数据库
use school;
— 显示二维表
show tables;
二、添加、修改表及表内容
— 创建二维表
create table tb_student(
stu_id int not null comment ‘学号’,
stu_name varchar(50) not null comment ‘姓名’,
stu_sex char(1) default ‘男’ comment ‘性别’,
stu_birth date comment ‘出生日期’,
primary key (stu_id)
) engine=innodb comment ‘学生表’;
— 查看表结构
desc tb_student;
— 删除表
drop table if exists tb_student;
— 修改表添加列
alter table tb_student add column stu_addr varchar(500) default ‘’ comment ‘家庭住址’;
alter table tb_student add column stu_tel char(11) not null comment ‘联系方式’;
— 修改表删除列
alter table tb_student drop column stu_tel;
— 修改表修改列
alter tab