– 如果存在就删除名为hrs的数据库
drop database if exists hrs
;
– 创建名为hrs的数据库并指定默认的字符集
create database hrs
default charset utf8mb4;
– 切换到hrs数据库
use hrs
;
– 创建部门表
create table tb_dept
(
dno
int not null comment ‘编号’,
dname
varchar(10) not null comment ‘名称’,
dloc
varchar(20) not null comment ‘所在地’,
primary key (dno
)
);
– 插入4个部门
insert into tb_dept
values
(10, ‘会计部’, ‘北京’),
(20, ‘研发部’, ‘成都’),
(30, ‘销售部’, ‘重庆’),
(40, ‘运维部’, ‘深圳’);
– 创建员工表
create table tb_emp
(
eno
int not null comment ‘员工编号’,
ename
varchar(20) not null comment ‘员工姓名’,
job
varchar(20) not null comment ‘员工职位’,
mgr
int comment ‘主管编号’,
sal
int not null comment ‘员工月薪’,