1 --建表 2 create table emp( 3 empno int primary key, 4 ename varchar(15) not null, 5 job varchar(20) not null, 6 mgr int, 7 hiredate date, 8 sal int, 9 comm int, 10 deptno int); 11 alter table emp add constraint emp_deptno_fk foreign key(deptno) references dept(deptno); 12 --插入数据 13 insert into emp values(7369,‘smith‘,‘clerk‘,7902,‘1980-12-17‘,800,null,20); 14 insert into emp values(7499,‘allen‘,‘salesman‘,7698,‘1981-02-20‘,1600,300,30); 15 insert into emp values(7521,‘ward‘,‘salesman‘,7698,‘1981-02-22‘,1250,500,30); 16 insert into emp values(7566,‘jones‘,‘manager‘,7839,‘1981-04-02‘,2975,null,20); 17 insert into emp values(7654,‘martin‘,‘salesman‘,7698,‘1981-09-28‘,1250,1400,30); 18 insert into emp values(7698,‘blake‘,‘manager‘,7839,‘1981-05-01‘,2850,null,30); 19 insert into emp values(7782,‘clark‘,‘manager‘,7839,‘1981-06-09‘,2450,null,10); 20 insert into emp values(7788,‘scott‘,‘analyst‘,7566,‘1987-04-19‘,3000,null,20); 21 insert into emp values(7839,‘king‘,‘president‘,null,‘1981-11-17‘,5000,null,10); 22 insert into emp values(7844,‘turner‘,‘salesman‘,7698,‘1981-09-08‘,1500,0,30); 23 insert into emp values(7876,‘adams‘,‘clerk‘,7788,‘1987-05-23‘,1100,null,20); 24 insert into emp values(7900,‘james‘,‘clerk‘,7698,‘1981-12-03‘,950,null,30); 25 insert into emp values(7902,‘ford‘,‘analyst‘,7566,‘1981-12-03‘,3000,null,20); 26 insert into emp values(7934,‘miller‘,‘clerk‘,7782,‘1982-01-23‘,1300,null,10);
1 --建表 2 create table dept( 3 deptno int primary key, 4 dname varchar(20), 5 loc varchar(20)); 6 --插入数据 7 insert into dept values(10,‘accounting‘,‘new york‘); 8 insert into dept values(20,‘research‘,‘dallas‘); 9 insert into dept values(30,‘sales‘,‘chicago‘); 10 insert into dept values(40,‘operations‘,‘boston‘);
1 --建表 2 create table salgrade( 3 grade int primary key, 4 losal int, 5 hisal int); 6 --插入数据 7 insert into salgrade values(1,700,1200); 8 insert into salgrade values(2,1201,1400); 9 insert into salgrade values(3,1401,2000); 10 insert into salgrade values(4,2001,3000); 11 insert into salgrade values(5,3001,9999);