사용자 도구

사이트 도구


기술문서:레퍼런스:쿼리:기본:일련번호_생성

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
기술문서:레퍼런스:쿼리:기본:일련번호_생성 [2026/06/19 10:45]
carlito76
기술문서:레퍼런스:쿼리:기본:일련번호_생성 [2026/08/25 17:10] (현재)
carlito76
줄 13: 줄 13:
  
 ===== 테이블 명세 ===== ===== 테이블 명세 =====
-^  물리명  ^  논리명  ^  타입  ^  길이  ^  KEY  ^+^  논리명  ^  물리명  ^  타입  ^  길이  ^  KEY  ^
 | 일련번호 | sn | 숫자형 | | PK | | 일련번호 | sn | 숫자형 | | PK |
 | 값 | value | 문자형 | 100 | | | 값 | value | 문자형 | 100 | |
  
 ===== MySQL/MariaDB ===== ===== MySQL/MariaDB =====
 +==== 자동 증가 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
 /* /*
줄 29: 줄 30:
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 자동 증가 
 INSERT INTO ex_serial_number (value) VALUES ('값'); INSERT INTO ex_serial_number (value) VALUES ('값');
 +</sxh>
 +
 +==== 시퀀스 ====
 +<sxh sql; gutter: true; title: DDL;>
 +CREATE TABLE ex_serial_number (
 + sn BIGINT NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +
 +/*
 + MariaDB 10.3 이상
 +*/
 +CREATE SEQUENCE ex_serial_number_seq
 + START WITH 1
 + INCREMENT BY 1
 + MINVALUE 1
 + MAXVALUE 9223372036854775806 -- 최댓값은 Signed BIGINT - 1
 + NOCYCLE
 + CACHE 20
 +;
 +</sxh>
 +
 +<sxh sql; gutter: true; title: DML;>
 +INSERT INTO ex_serial_number (sn, value) VALUES (NEXT VALUE FOR ex_serial_number_seq, '값');
 +-- INSERT INTO ex_serial_number (sn, value) VALUES (NEXTVAL('ex_serial_number_seq'), '값');
 </sxh> </sxh>
  
 ===== MSSQL ===== ===== MSSQL =====
 +==== 자동 증가 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
 /* /*
줄 45: 줄 71:
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 자동 증가 
 INSERT INTO ex_serial_number (value) VALUES ('값'); INSERT INTO ex_serial_number (value) VALUES ('값');
 </sxh> </sxh>
  
-===== Oracle/Tibero =====+==== 시퀀스 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
-/* 
- Oracle 8i 이상/Tibero 6 이상 
-*/ 
 CREATE TABLE ex_serial_number ( CREATE TABLE ex_serial_number (
- sn NUMBER NOT NULL PRIMARY KEY,+ sn BIGINT NOT NULL PRIMARY KEY,
  value VARCHAR(100) NOT NULL  value VARCHAR(100) NOT NULL
 ); );
  
 +/*
 + MSSQL 2012 이상
 +*/
 CREATE SEQUENCE ex_serial_number_seq CREATE SEQUENCE ex_serial_number_seq
 + AS BIGINT
  START WITH 1  START WITH 1
  INCREMENT BY 1  INCREMENT BY 1
  MINVALUE 1  MINVALUE 1
- MAXVALUE 9999999999999999999999999999 -- 최댓값은 양의 정수 28자리 + MAXVALUE 9223372036854775806 -- 최댓값은 Signed BIGINT - 1 
- NOCYCLE+ NO CYCLE
  CACHE 20  CACHE 20
- NOORDER 
 ; ;
 </sxh> </sxh>
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 시퀀스 +INSERT INTO ex_serial_number (sn, value) VALUES (NEXT VALUE FOR ex_serial_number_seq, '값');
-INSERT INTO ex_serial_number (sn, value) VALUES (ex_serial_number_seq.NEXTVAL, '값');+
 </sxh> </sxh>
  
 +===== Oracle/Tibero =====
 +==== 자동 증가 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
 -- Oracle 12c 이상 -- Oracle 12c 이상
줄 84: 줄 110:
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 자동 증가 
 INSERT INTO ex_serial_number (value) VALUES ('값'); INSERT INTO ex_serial_number (value) VALUES ('값');
 +</sxh>
 +
 +==== 시퀀스 ====
 +<sxh sql; gutter: true; title: DDL;>
 +CREATE TABLE ex_serial_number (
 + sn NUMBER NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +
 +/*
 + Oracle 8i 이상/Tibero 6 이상
 +*/
 +CREATE SEQUENCE ex_serial_number_seq
 + START WITH 1
 + INCREMENT BY 1
 + MINVALUE 1
 + MAXVALUE 9999999999999999999999999999 -- 최댓값은 양의 정수 28자리
 + NOCYCLE
 + CACHE 20
 + NOORDER
 +;
 +</sxh>
 +
 +<sxh sql; gutter: true; title: DML;>
 +INSERT INTO ex_serial_number (sn, value) VALUES (ex_serial_number_seq.NEXTVAL, '값');
 </sxh> </sxh>
  
 ===== PostgreSQL ===== ===== PostgreSQL =====
 +==== 자동 증가 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
 /* /*
줄 108: 줄 159:
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 자동 증가 
 INSERT INTO ex_serial_number (value) VALUES ('값'); INSERT INTO ex_serial_number (value) VALUES ('값');
 +</sxh>
 +
 +==== 시퀀스 ====
 +<sxh sql; gutter: true; title: DDL;>
 +CREATE TABLE ex_serial_number (
 + sn BIGINT NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +
 +/*
 + PostgreSQL 6.0 이상
 +*/
 +CREATE SEQUENCE ex_serial_number_seq
 + START WITH 1
 + INCREMENT BY 1
 + MINVALUE 1
 + MAXVALUE 9223372036854775806 -- 최댓값은 Signed BIGINT - 1
 + NO CYCLE
 + CACHE 20
 +;
 +
 +/*
 + PostgreSQL 10.0 이상
 +*/
 +CREATE SEQUENCE ex_serial_number_seq
 + AS BIGINT
 + START WITH 1
 + INCREMENT BY 1
 + MINVALUE 1
 + MAXVALUE 9223372036854775806 -- 최댓값은 Signed BIGINT - 1
 + NO CYCLE
 + CACHE 20
 +;
 +</sxh>
 +
 +<sxh sql; gutter: true; title: DML;>
 +INSERT INTO ex_serial_number (sn, value) VALUES (NEXTVAL('ex_serial_number_seq'), '값');
 </sxh> </sxh>
  
 {{tag>"쿼리" "Query" "기본"}} {{tag>"쿼리" "Query" "기본"}}