alter
제약조건 변경
테이블 (제약조건) 추가
- 제약조건 없이 테이블 생성했을 때 제약조건 추가
- alter table 테이블이름 add constraint 제약조건이름 제약조건(컬럼);
alter table classes add constraint classes_PK_cno PRIMARY KEY(cno);
- add constraint : 제약조건을 추가하겠다.
- classes_PK_cno : 별칭
모든 테이블에 있는 pk를 몰아볼 수 있다. 그래서 별칭을 주로 아래와 같은 규칙으로 생성한다.
테이블 (제약조건) 수정
- alter table 테이블이름 MODIFI 컬럼명 제약조건;
alter table classes MODIFI cname NOT NULL;
테이블 (제약조건) 이름 변경
- alter table 테이블이름 rename constraint 이름 to 새이름;
alter table classes rename constraint classesPKcno to classesNNcno;
테이블 (제약조건) 삭제
- alter table 테이블이름 drop constraint 컬럼명;
alter table classes drop constraint classesPKcno;
컬럼 변경
컬럼 추가
- alter table 테이블명 add 컬럼명 자료형;
alter table teacher add T_GENDER varchar2(10);
컬럼명 변경
- alter table 테이블명 rename column 이전컬럼명 to 변경할컬럼명;
alter table teacher rename column T_GEN to T_GENDER;
자료형 변경
- alter table 테이블명 MODIFI 컬럼명 자료형;
alter table teacher MODIFI T_GENDER varchar2(20);
열 삭제
- alter table 테이블명 drop column 컬럼명;
alter table teacher drop column T_GENDER;