티스토리 뷰

공부

[Oracle] AUTO_INCREMENT

승가비 2019. 10. 4. 00:17
728x90
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

728x90

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

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