본문 바로가기

Oracle/SQL

SQL (3) 제약 NOT NULL 제약

NULL 값데이터 ————> 결측치

데이터 분석시 데이터 전처리시에 반드시 확인해야하는 2가지 데이터가 있는데

  1. 결측치
  2. 이상치

 

NOT NULL 제약 거는방법 2가지

1. 테이블 생성시 제약 거는방법

create table emp407
(empno number(10) constraint emp407_empno_mm not null,
ename varchar2(10));

2. 만들어진 테이블에 제약 거는방법

alter table 테이블명
modify 컬럼명 constraint 제약이름 제약명 ;

alter table dept
modify dname constraint dept_dname_nn not null;

→ 기존 pk, un 와 다른 점은 add 가 아니라 modify 를 쓴다는 것.

만약 제약을 삭제한다면?

alter table emp14
drop constraint emp14_email_nn;

EMP 에 걸린 제약 확인하기

select T.table_name, T.constraint_name, C.column_name, T.constraint_type
from user_constraints t , user_cons_columns c
where t.constraint_name = c.constraint_name
and t.table_name = 'EMP';

확인하고 지우고 싶은제약이있다면

선택하고

ALTER TABLE EMP
DROP CONSTRAINT EMP_EMPNO_PK;
ALTER TABLE EMP
DROP CONSTRAINT EMP_NAME_UN;

각각지워주면 됩니다~