create tables:
create table LOC (LOCID
int,CITY varchar2(16),constraint pk_loc primary key (locid));
create table DEPT (DEPID
int,DEPTNAME varchar2(16),LOCID int,constraint pk_dept primary key
(depid),constraint fk_dept_loc foreign key (locid) references loc(locid));
create table EMP (EMPID
int,EMPNAME varchar2(16),DEPID int,constraint pk_emp primary key
(empid),constraint fk_emp_dept foreign key (depid) references dept(depid));
Show constraints:
SQL>
select CONSTRAINT_NAME, CONSTRAINT_TYPE,TABLE_NAME,R_CONSTRAINT_NAME from user_constraints;
CONSTRAINT_NAME
C TABLE_NAME R_
CONSTRAINT_NAME
FK_EMP_DEPT
R EMP
PK_DEPTFK_DEPT_LOC R DEPT
PK_LOCPK_LOC P LOC
PK_DEPT P DEPT
PK_EMP P
No comments:
Post a Comment