SQL/Redshift
Redshift : alter table ~ drop column ~ (column 삭제, column 제거)
CosmosProject
2022. 10. 19. 19:50
728x90
반응형
alter table 구문을 이용해서 table에 존재하는 column을 삭제할 수 있습니다.
Syntax
alter table (table_name) drop column (column_name)
(table_name) = 변경 사항을 적용할 table 이름입니다.
(column_name) = 삭제할 column의 이름입니다.
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
drop column col3
;
위 쿼리를 실행하면 col3라는 이름의 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,
col4 timestamp without time zone ENCODE az64
)
DISTSTYLE AUTO;
잘 삭제되었는지 보기 위해 show table 구문을 이용해서 table의 정보를 보면 위와 같습니다.
col3가 없어진 것을 볼 수 있습니다.
728x90
반응형