● check 제약조건
**[ex1]
salary number(10),
constraint xxxx check(salary >0 ),
(==)
salary number(10) constraint xxxx check (salary > 0),
/*********************************************************/
**[ex2]
number타입일경우 '020101'경우 앞자리 '0'이 입력안됨
주민번호 varchar2(13),
constraint xxx check (length(주민번호) = 13),
/*table-level*/
/*주민번호 insert, update시에 입력값이 13자리일때에만 작동*/
(==)
주민번호 varchar2(13) constraint xxx check (length(주민번호) = 13),
/*column-level*/
/*"," 콤마 하나다름*/
/*********************************************************/
**[ex3]
성별 varchar2(10),
constraint xxxx check (성별 = '남' or 성별 = '여'),
(==)
성별 varchar2(10),
constraint xxxx check (성별 in ('남', '여')),
(==)
성별 varchar2(10) constraint xxxx check (성별 in ('남', '여')),
제약조건명 명시시
ex) 'emp1_employee_id primarykey'
ex) 'emp1_last_name_nn not null'
table_column_attribute + 제약조건으로 선언하는것이 일반적
연습문제
create table title
(title_id number(10) constraint ttl_tid_pk primary key,
title varchar2(60) constraint ttl_ttl_nn not null,
description varchar2(400) constraint ttl_desc_nn not null,
rating varchar2(4) CONSTRAINT ttl_rat_ck check (rating in ('g','pg','r','nc17','nr')),
category varchar2(20) constraint ttl_cate_ck
check(category in ('drama', 'comedy', 'action',
'child', 'scifi', 'documentary')),
release_date date);
create table title_copy
(copy_id number(10),
title_id number(10) constraint tcopy_tid_fk references title(title_id),
status varchar2(15) constraint tcopy_st_ch
check (status in ('available', 'destroyed', 'rented', 'reserved'))
constraint tcopy_st_nn not null,
CONSTRAINT tcopy_pk PRIMARY KEY(copy_id, title_id));
'ㆍDatabase' 카테고리의 다른 글
[MySQL] MySQL 데이터 형식 (0) | 2022.03.25 |
---|---|
[오라클/ORACLE]테이블삭제/절단/복구 - DROP/TRUNCATE/FLASHBACK (0) | 2021.09.13 |
[오라클/oracle] like 비교연산자 & 연습문제 (0) | 2021.09.11 |
[오라클/oracle] 서브쿼리 맛보기 (0) | 2021.09.11 |
[오라클/oracle] 제약조건 유형 (0) | 2021.09.11 |