반응형


1. PK, FK 설정 예제

CREATE TABLE dept
(deptno NUMBER(2),
dname VARCHAR2(15),
loc VARCHAR2(15),
CONSTRAINT dept_deptno_pk PRIMARY KEY(deptno));

CREATE TABLE emp
(empno NUMBER(4),
ename VARCHAR2(15),
deptno NUMBER(2),
CONSTRAINT emp_empno_pk PRIMARY KEY(empno),
CONSTRAINT emp_deptno_fk FOREIGN KEY(deptno) REFERENCES dept(deptno));

2. 제약조건 설정 확인

SELECT table_name, constraint_type, constraint_name, r_constraint_name
FROM user_constraints
WHERE table_name IN('EMP','DEPT');

반응형