SQL/Redshift

Redshift : alter table ~ add ~ (column 추가, column 추가하기)

CosmosProject 2022. 10. 19. 19:43
728x90
반응형

 

 

 

alter table 구문을 이용해서 table에 새로운 컬럼을 추가해봅시다.

 

 

Syntax

alter table (table_name) add (column_name) (data_type)

 

(table_name) = 변경 사항을 적용할 table 이름입니다.

 

(column_name) = 새롭게 추가할 column의 이름입니다.

 

(data_type) = 새롭게 추가할 column의 data type입니다.

 

 

 

 

 

create table test_schema.test_table (
    col1       bigint,
    col2       varchar(60),
    col3       date,
    col4       timestamp
)
;

 

 

테스트를 위해 위처럼 test_schema.test_table을 생성합시다.

 

column은 col1, col2, col3, col4 총 4개가 존재합니다.

 

 

 

alter table test_schema.test_table
add col5 varchar(360)
;

 

위 쿼리를 실행하면 varchar(360) type인 col5라는 이름의 column이 test_schema.test_table 테이블에 추가됩니다.

 

 

 

 

 

 

 

show table test_schema.test_table;



-- Result
CREATE TABLE test_sch.test_table (
    col1 bigint ENCODE az64,
    col2 character varying(60) ENCODE lzo,
    col3 date ENCODE az64,
    col4 timestamp without time zone ENCODE az64,
    col5 character varying(360) ENCODE lzo
)
DISTSTYLE AUTO;

 

잘 추가되었는지 보기 위해 show table 구문을 이용해서 table의 정보를 보면 위와 같습니다.

 

col5가 추가된 것을 볼 수 있으며 col5의 data type은 varchar(= varying character)이며 최대 길이가 360입니다.

 

 

 

 

 

 

728x90
반응형