사용자 도구

사이트 도구


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

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
기술문서:레퍼런스:쿼리:기본:일련번호_생성 [2025/08/12 11:22]
carlito76
기술문서:레퍼런스:쿼리:기본:일련번호_생성 [2026/08/25 17:10] (현재)
carlito76
줄 7: 줄 7:
  
 <note tip> <note tip>
-최소 지원 버전은 약간의 차이가 있을 수 있습니다.+최소 지원 버전은 약간의 차이가 있을 수 있습니다.\\ 
 +- MySQL/MariaDB, PostgreSQL: 세부 버전까지 표시\\ 
 +- MSSQL, Oracle/Tibero: 제품 버전까지 표시
 </note> </note>
  
-^  물리명  ^  논리명  ^  타입  ^  KEY  ^ +===== 테이블 명세 ===== 
-| 일련번호 | sn | 숫자형 | PK | +^  논리명  ^  물리명  ^  타입  ^  길이  ^  KEY  ^ 
-| 값 | value | 문자형 | |+| 일련번호 | sn | 숫자형 | | PK | 
 +| 값 | value | 문자형 | 100 | |
  
 ===== MySQL/MariaDB ===== ===== MySQL/MariaDB =====
 +==== 자동 증가 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
--- MySQL 3.0 이상/MariaDB 5.1 이상+/* 
 + MySQL 3.0 이상/MariaDB 5.1 이상 
 +*/
 CREATE TABLE ex_serial_number ( CREATE TABLE ex_serial_number (
  sn BIGINT AUTO_INCREMENT NOT NULL PRIMARY KEY,  sn BIGINT AUTO_INCREMENT NOT NULL PRIMARY KEY,
줄 24: 줄 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;>
--- MSSQL 7.0 이상+/* 
 + MSSQL 7.0 이상 
 +*/
 CREATE TABLE ex_serial_number ( CREATE TABLE ex_serial_number (
  sn BIGINT IDENTITY (1, 1) NOT NULL PRIMARY KEY,  sn BIGINT IDENTITY (1, 1) NOT NULL PRIMARY KEY,
줄 38: 줄 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 sql; gutter: true; title: DDL;>
 +CREATE TABLE ex_serial_number (
 + sn BIGINT NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +
 +/*
 + MSSQL 2012 이상
 +*/
 +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 (NEXT VALUE FOR ex_serial_number_seq, '값');
 </sxh> </sxh>
  
 ===== Oracle/Tibero ===== ===== Oracle/Tibero =====
 +==== 자동 증가 ====
 +<sxh sql; gutter: true; title: DDL;>
 +-- Oracle 12c 이상
 +CREATE TABLE ex_serial_number (
 + sn NUMBER GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +</sxh>
 +
 +<sxh sql; gutter: true; title: DML;>
 +INSERT INTO ex_serial_number (value) VALUES ('값');
 +</sxh>
 +
 +==== 시퀀스 ====
 <sxh sql; gutter: true; title: DDL;> <sxh sql; gutter: true; title: DDL;>
 CREATE TABLE ex_serial_number ( CREATE TABLE ex_serial_number (
줄 49: 줄 120:
 ); );
  
--- Oracle 8i 이상/Tibero 6 이상+/* 
 + Oracle 8i 이상/Tibero 6 이상 
 +*/
 CREATE SEQUENCE ex_serial_number_seq CREATE SEQUENCE ex_serial_number_seq
  START WITH 1  START WITH 1
줄 62: 줄 135:
  
 <sxh sql; gutter: true; title: DML;> <sxh sql; gutter: true; title: DML;>
--- 시퀀스 
 INSERT INTO ex_serial_number (sn, value) VALUES (ex_serial_number_seq.NEXTVAL, '값'); 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;>
--- PostgreSQL 8.4 이상+/* 
 + PostgreSQL 8.4 이상 
 +*/
 CREATE TABLE ex_serial_number ( CREATE TABLE ex_serial_number (
  sn BIGSERIAL NOT NULL PRIMARY KEY,  sn BIGSERIAL NOT NULL PRIMARY KEY,
 + value VARCHAR(100) NOT NULL
 +);
 +
 +/*
 + PostgreSQL 10 이상
 +*/
 +CREATE TABLE ex_serial_number (
 + sn BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY,
  value VARCHAR(100) NOT NULL  value VARCHAR(100) NOT NULL
 ); );
줄 76: 줄 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>
 +
 +==== 시퀀스 ====
 +<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>
 +
 +{{tag>"쿼리" "Query" "기본"}}