본문 바로가기
ORACLE

[ORACLE] alter table ..... 테이블관련 생성 / 변경 / 삭제

by DBA 드굔 2023. 4. 14.
반응형

1. Oracle Table 수정/추가/삭제 등등

Oracle DB 및 다른 DB도 마찬가지로 운영하다 보면 Table에 대한 변경 작업을 하기 마련입니다. 오늘은 헷갈릴수도 있는 
테이블 수정 명령을 확인해 보겠습니다.

1. Table에 컬럼 추가

alter table [TB_NAME] add (컬럼명 데이터타입(데이터크기));

ex) alter table scott.test_table add test_col1 varchar2(30);

혹은 여러 컬럼을 추가할때 

ex) alter table scott.test_table add 
(test_col1 varchar2(30), 
test_col2 varchar2(1), 
test_col3 date );

 

2. Table 컬럼 속성 변경 및 data 크리 resize

alter table [TB_NAME] modify (컬럼명 데이터타입(데이터크기));

ex) alter table scott.test_table modify test_col1 varchar2(35);

or

alter table scott.test_table modify test_col1 number(35);

위에서 보듯  데이터 타입의 크기 뿐만 아니라 Datatype도 변경이 가능 하지만 테이블 내에 데이터가 있을 경우 변경이 가능 한지 미리 확인 해야 합니다.

3. Table 컬럼명 변경

alter table [TB_NAME] rename column 컬럼명 to 변경할 컬럼명;

ex) alter table scott.test_table rename column test_col1 to test_col10;

4. Table 컬럼 삭제

alter table [TB_NAME] drop column 컬럼명;

ex) alter table scott.test_table drop column test_col1;
반응형

댓글