敲代码不易,求个点赞!!!
create database test1;
use test1;
create table dept(
deptno int primary key,
dname varchar(14),
loc varchar(13)
);
insert into dept values ( 10, 'accounting', 'new york' );
insert into dept values ( 20, 'research' , 'dallas' );
insert into dept values ( 30, 'sales' , 'chicago' );
insert into dept values (40, 'operations' , 'boston' );
CREATE TABLE emp(
empno int primary key, -- 员工编号
ename varchar(10), -- 员工姓名
job varchar(9), -- 员工工作
mgr int, -- 员工直属领导编号
hiredate date, -- 入职时间
sal double, -- 工资
comm double, -- 奖金
deptno int -- 对应dept表的外键
);
-- 添加部门和员工之间的主外键关系
ALTER TABLE emp add constraint foreign key emp(deptno) references dept(deptno);
insert into emp values(7369, 'smith' , 'clerk',7902,'1980-12-17',800,null,20);
insert into emp values(7499, 'allen' , 'salesman' ,7698,'1981-02-20',1600,300,30);
insert into emp values(7521, 'ward' , 'salesman',7698,'1981-02-22',1250,500,30);
insert into emp values(7566,'jones' , 'manager',7839,'1981-04-02',2975,null,20);
insert into emp values(7654, 'martin' , 'salesman',7698,'1981-09-28',1250,1400,30);
insert into emp values(7698, 'blake' , 'manager' ,7839,'1981-05-01 ',2850,null,30);
insert into emp values(7782,'clark' , 'manager',7839,'1981-06-09',2450,null,10);
insert into emp values(7788, 'scott' , 'analyst',7566,'1987-07-03' , 3000,null,20);
insert into emp values(7839, 'king' , 'president' , null,'1981-11-17',5000,null,10);
insert into emp values(7844, 'turner' , 'salesman' ,7698,'1981-09-08',1500,0,30);
insert into emp values(7876, 'adams' , 'clerk',7788,'1987-07-13',1100,null,20);
insert into emp values(7900, 'james' , 'clerk',7698,'1981-12-03' ,950,null,30);
insert into emp values(7902, 'ford' , 'analyst' ,7566,'1981-12-03',3000,null,20);
insert into emp values(7934, 'miller' , 'clerk',7782,'1981-01-23',1300,null,10);
create table salgrade(
grade int, -- 等级
losal double, -- 最低工资
hisal double
); -- 最高工资
insert into salgrade values (1,700,1200);
insert into salgrade values ( 2,1201,1400) ;
insert into salgrade values ( 3,1401,2000) ;
insert into salgrade values (4,2001,3000);
insert into salgrade values ( 5,3001, 9999);