- 엔티티 제약조건 (UNIQUE, PRIMARY KEY)
CONSTRAINT 제약조건명 PRIMARY KEY(컬럼명)
CREATETABLE NOTICES
(
SEQ VACHAR2(10) PRIMARY KEY, -- 기본키 제약 조건
TITLE VARCHAR2(300) NOT NULL, -- NOT NULL
WRITER VARCHAR2(50) NOT NULL UNIQUE, -- NOT NULL/UNIQUE
CONTEN VARCHAR2(4000),
REGDATE DATE DEFAULT SYSDATE, -- 기본값 현재날짜
HIT NUMBER DEFALT 0 -- 기본값 0
)
CREATETABLE NOTICES
(
SEQ VACHAR2(10) CONSTRAINT NOTICES_SEQ_PK PRIMARY KEY,
TITLE VARCHAR2(300) NOT NULL, -- NOT NULL
WRITER VARCHAR2(50) NOT NULL UNIQUE, -- NOT NULL/UNIQUE
CONTEN VARCHAR2(4000),
REGDATE DATE DEFAULT SYSDATE, -- 기본값 현재날짜
HIT NUMBER DEFALT 0 -- 기본값 0
)
CREATETABLE NOTICES
(
SEQ VACHAR2(10),
TITLE VARCHAR2(300) NOT NULL, -- NOT NULL
WRITER VARCHAR2(50) NOT NULL, -- NOT NULL
CONTEN VARCHAR2(4000),
REGDATE DATE DEFAULT SYSDATE, -- 기본값 현재날짜
HIT NUMBER DEFALT 0 -- 기본값 0
CONSTRAINT NOTICES_SEQ_PK PRIMARY KEY(SEQ)
CONSTRAINT NOTICES_SEQ_UK UNIQUE(WRITER)
)
- 릴레이션 제약조건 (FOREIGN KEY)
CREATETABLE NOTICES
(
SEQ VACHAR2(10),
TITLE VARCHAR2(300) NOT NULL, -- NOT NULL
WRITER VARCHAR2(50) NOT NULL, -- NOT NULL
CONTEN VARCHAR2(4000),
REGDATE DATE DEFAULT SYSDATE, -- 기본값 현재날짜
HIT NUMBER DEFALT 0 -- 기본값 0
CONSTRAINT NOTICES_SEQ_PK PRIMARY KEY(SEQ)
CONSTRAINT NOTICES_SEQ_UK UNIQUE(WRITER)
CONSTRAINT NOTICES_SEQ_FK FOREIGN KEY(WRITER) REFERENCES MEMBERS(MID) -- 참조 제약조건
)
ALTER TABLE 테이블명
ADD CONSTRAINT 제약조건명
FOREIGN KEY(컬럼명) REFERENCES 참조테이블명(참조컬럼명)
ALTER TABLE TEST3
ADD CONSTRAINT NOTICES_WRITER_FK
FOREIGN KEY(WRITER) REFERENCES MEMBERS(MID) -- 참조하는 컬럼이 PRIMARY KEY 이어야 함