create table DEPT
(
DEPTNO number(2) not null,
DNAME varchar(14),
LOC varchar(13)
)
;
alter table DEPT
add constraint PK_DEPT primary key (DEPTNO);
create table EMP
(
EMPNO number(4) not null,
ENAME varchar(10),
JOB varchar(9),
MGR number(4),
HIREDATE date,
SAL number(7 ),
COMM number(7 ),
DEPTNO number(2)
)
;
alter table EMP
add constraint PK_EMP primary key (EMPNO);
alter table EMP
add constraint FK_DEPTNO foreign key (DEPTNO)
references DEPT (DEPTNO);
insert into DEPT (DEPTNO,DNAME,LOC)
values (10,'ACCOUNTING','NEW YORK');
insert into DEPT (DEPTNO,LOC)
values (20,'RESEARCH','DALLAS');
insert into DEPT (DEPTNO,LOC)
values (30,'SALES','CHICAGO');
insert into DEPT (DEPTNO,LOC)
values (40,'OPERATIONS','BOSTON');
commit;
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
values (7369,'SMITH','CLERK',7902,to_date('1980-12-17','YYYY-MM-DD'),800,null,20);
insert into EMP (EMPNO,DEPTNO)
values (7499,'ALLEN','SALESMAN',7698,to_date('1981-02-20',1600,300,30);
insert into EMP (EMPNO,DEPTNO)
values (7521,'WARD',to_date('1981-02-22',1250,500,DEPTNO)
values (7566,'JONES','MANAGER',7839,to_date('1981-04-02',2975,DEPTNO)
values (7654,'MARTIN',to_date('1981-09-28',1400,DEPTNO)
values (7698,'BLAKE',to_date('1981-05-01',2850,DEPTNO)
values (7782,'CLARK',to_date('1981-06-09',2450,10);
insert into EMP (EMPNO,DEPTNO)
values (7788,'SCOTT','ANALYST',7566,to_date('1987-04-19',3000,DEPTNO)
values (7839,'KING','PRESIDENT',to_date('1981-11-17',5000,DEPTNO)
values (7844,'TURNER',to_date('1981-09-08',1500,DEPTNO)
values (7876,'ADAMS',7788,to_date('1987-05-23',1100,DEPTNO)
values (7900,'JAMES',to_date('1981-12-03',950,DEPTNO)
values (7902,'FORD',to_date('1981-12-02',DEPTNO)
values (7934,'MILLER',7782,to_date('1982-01-23',1300,10);
commit;
来自:http://blog.sina.com.cn/s/blog_6d76c7e20102v081.html
原文链接:https://www.f2er.com/oracle/207856.html