当前位置:网站首页>MySQL winter vacation self-study 2022 11 (9)

MySQL winter vacation self-study 2022 11 (9)

2022-07-05 03:13:00 Crane paper thousand

Code preparation for multi table query exercise

--  establish test1 database 
create database test1;
--  Choose to use test1 database 
use test1;
--  Create department table 
create table dept(
	deptno int primary key comment ' Department number ',
  dname varchar(14) comment ' Department name ',
  loc varchar(13) comment ' Department Address '
);

insert into dept values(10,'accounting','new york'),
(20,'research','dallas'),
(30,'sales','chicago'),
(40,'operations','boston');

--  Create an employee table 
create table emp(
		empno int primary key comment ' Employee number ',
    ename varchar(10) comment ' Employee name ',
    job varchar(9) comment ' Staff work ',
    mgr int comment ' Employee's direct leader No ',
    hiredate date comment ' Entry time ',
    sal double comment ' Wages ',
    comm double comment ' Bonus ',
    deptno int comment ' Corresponding dept Table foreign key '
);
--  Add foreign key relationships between departments and employees 
alter table emp add constraint foreign key emp(deptno) references dept (deptno);

--  Create a pay scale 
create table salgrade(
		grand int comment ' Grade ',
    losal double comment ' minimum wage ',
    hisal double comment ' Maximum wage '
);
insert into salgrade values (1,700,1200),(2,1201,1400),(3,1401,2000),(4,2001,3000),(5,3001,9999);

insert into emp values
(7369,'smith','clerk' 7902,'1980-12-17',800,null,20),
(7499,'allen','salesman',7698,'1981-02-20',1600,300,30),
(7521,'ward','salesman',7698,'1981-02-22',1250,500,30);
(7566,'JONES','MANAGER',7839,'1981-04-02',2975,NULL,20),
(7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30),
(7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,NULL,30),
(7782,'CLARK','MANAGER',7839,'1981-06-09',2450,NULL,10),
(7788,'SCOTT','ANALYST',7566,'1987-04-19',3000,NULL,20),
(7839,'KING','PRESIDENT',NULL,'1981-11-17',5000,NULL,10),
(7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30),
(7876,'ADAMS','CLERK',7788,'1987-05-23',1100,NULL,20),
(7900,'JAMES','CLERK',7698,'1981-12-03',950,NULL,30),
(7902,'FORD','ANALYST',7566,'1981-12-03',3000,NULL,20),
(7934,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,10);

原网站

版权声明
本文为[Crane paper thousand]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140803353535.html