티스토리 뷰

공부

[Oracle] AUTO_INCREMENT

seunggabi 승가비 2019. 10. 4. 00:17
CREATE TABLE test (
  id NUMBER(10) NOT NULL
);

ALTER TABLE test ADD (
  CONSTRAINT dept_pk PRIMARY KEY (ID)
);

CREATE SEQUENCE test_seq START WITH 1;

CREATE OR REPLACE TRIGGER test_trg 
BEFORE INSERT ON test 
FOR EACH ROW

BEGIN
  SELECT test_seq.NEXTVAL
  INTO   :new.id
  FROM   dual;
END;
/

 

[출처] https://stackoverflow.com/questions/11296361/how-to-create-id-with-auto-increment-on-oracle

'공부' 카테고리의 다른 글

[Linux] change user password  (0) 2019.10.14
[Shell] Search line's text in file  (0) 2019.10.11
[Oracle] AUTO_INCREMENT  (0) 2019.10.04
[Git] Account information  (0) 2019.08.29
[CSS] 다음 카페 움직이는  (0) 2019.08.29
[SH] Shell equal  (0) 2019.08.20
댓글
댓글쓰기 폼