■ SEQUENCE를 사용해 자동 증가 컬럼 생성하기

------------------------------------------------------------------------------------------------------------------------

 

CREATE SEQUENCE ID_SEQUENCE;

 

CREATE TABLE SAMPLE_TABLE

(

    ID   INTEGER NOT NULL DEFAULT NEXTVAL('ID_SEQUENCE')

   ,NAME VARCHAR(100)

);

 

ALTER SEQUENCE ID_SEQUENCE OWNED BY SAMPLE_TABLE.ID;

 

 

※ 이미 존재하는 테이블의 컬럼 적용시

 

CREATE SEQUENCE ID_SEQUENCE;

 

ALTER TABLE SAMPLE_TABLE ALTER COLUMN ID SET DEFAULT NEXTVAL('ID_SEQUENCE');

 

ALTER SEQUENCE ID_SEQUENCE OWNED BY SAMPLE_TABLE.ID;

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG