--- id: sql-auto-increment title: "SQL Auto Increment" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL AUTO INCREMENT Field", "AUTO_INCREMENT", "IDENTITY", "AUTOINCREMENT", "SEQUENCE"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "autoincrement", "primarykey"] raw_sources: ["https://www.w3schools.com/sql/sql_autoincrement.asp"] applied_in: [] github_commit: "" --- # [[SQL Auto Increment]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) Every vendor auto-generates unique primary key numbers, but under a different keyword and mechanism โ€” MySQL's AUTO_INCREMENT, SQL Server's IDENTITY, Access's AUTOINCREMENT, and Oracle's standalone SEQUENCE object requiring an explicit nextval() call. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **Auto-increment field** โ€” a numeric column that automatically generates a unique number when a new record is inserted; typically the PRIMARY KEY. [S1] - **MySQL** โ€” `AUTO_INCREMENT` keyword; default start 1, increments by 1; restart value via `ALTER TABLE ... AUTO_INCREMENT = 100;`. [S1] - **SQL Server** โ€” `IDENTITY(seed, increment)`, e.g. `IDENTITY(1,1)`. [S1] - **MS Access** โ€” `AUTOINCREMENT` keyword, optionally `AUTOINCREMENT(seed, increment)`. [S1] - **Oracle** โ€” no inline keyword; requires a standalone `SEQUENCE` object and explicit `sequence.nextval` on insert. [S1] ## ๐Ÿงฉ ์ถ”์ถœ๋œ ํŒจํ„ด (Extracted patterns) - **Insert without specifying the key** โ€” in MySQL/SQL Server/Access, an INSERT simply omits the auto-increment column and the value is generated automatically. [S1] - **Oracle is the odd one out** โ€” Oracle requires you to explicitly reference `seq_person.nextval` in the INSERT statement itself, rather than the column being silently populated. [S1] ## โš–๏ธ ๋น„๊ต ๋ฐ ์„ ํƒ ๊ธฐ์ค€ (Comparison & decision criteria) | ํ•ญ๋ชฉ (Option) | ์žฅ์  | ๋‹จ์  | ์–ธ์ œ ์„ ํƒ | |---|---|---|---| | **MySQL AUTO_INCREMENT / SQL Server IDENTITY / Access AUTOINCREMENT** | ์ปฌ๋Ÿผ ์ •์˜๋งŒ์œผ๋กœ ์ž๋™ ์ƒ์„ฑ, INSERT๊ฐ€ ๊ฐ„๋‹จ | ๋ฒค๋” ์ข…์† ๋ฌธ๋ฒ• | ํ•ด๋‹น ๋ฒค๋” ์‚ฌ์šฉ ์‹œ ๊ธฐ๋ณธ ์„ ํƒ | | **Oracle SEQUENCE** | ์—ฌ๋Ÿฌ ํ…Œ์ด๋ธ”์ด ๊ณต์œ  ๊ฐ€๋Šฅ, ์„ธ๋ฐ€ํ•œ ์ œ์–ด(cache, start, increment) | INSERT๋งˆ๋‹ค `.nextval` ๋ช…์‹œ ํ•„์š”, ๋ณ„๋„ ๊ฐ์ฒด ๊ด€๋ฆฌ | Oracle ์‚ฌ์šฉ ์‹œ ์œ ์ผํ•œ ๋ฐฉ๋ฒ• | ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - MySQL: `CREATE TABLE Persons (Personid int AUTO_INCREMENT PRIMARY KEY, ...);`. [S1] - SQL Server: `CREATE TABLE Persons (Personid int IDENTITY(1,1) PRIMARY KEY, ...);`. [S1] - Oracle: `CREATE SEQUENCE seq_person MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10;` then `INSERT INTO Persons (Personid, FirstName, LastName) VALUES (seq_person.nextval, 'Lars', 'Monsen');`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **๋ฒค๋” 4๊ฐœ ๋ชจ๋‘ ๋ฌธ๋ฒ•์ด ๋‹ค๋ฆ„**: ๋™์ผํ•œ "์ž๋™ ์ฆ๊ฐ€" ์š”๊ตฌ๊ฐ€ AUTO_INCREMENT/IDENTITY/AUTOINCREMENT/SEQUENCE๋กœ ์™„์ „ํžˆ ๋‹ค๋ฅด๊ฒŒ ๊ตฌํ˜„๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” PRIMARY KEY ์ปฌ๋Ÿผ์— ๊ฐ’์„ ์ˆ˜๋™ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  ์ž๋™ ์ƒ์„ฑํ•˜๊ณ  ์‹ถ์„ ๋•Œ ํ‘œ์ค€์ ์œผ๋กœ ์“ฐ์ด๋Š” ํŒจํ„ด์ด๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) MySQL and Oracle equivalents (SQL): ```sql -- MySQL CREATE TABLE Persons ( Personid int AUTO_INCREMENT PRIMARY KEY, LastName varchar(255) NOT NULL ); -- Oracle CREATE SEQUENCE seq_person MINVALUE 1 START WITH 1 INCREMENT BY 1 CACHE 10; INSERT INTO Persons (Personid, FirstName, LastName) VALUES (seq_person.nextval, 'Lars', 'Monsen'); ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.87 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[SQL Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[SQL Primary Key]], [[SQL Insert Into]], [[SQL Create Table]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** PRIMARY KEY ๊ฐ’์„ ์ž๋™ ์ƒ์„ฑํ•ด์•ผ ํ•  ๋•Œ ์‚ฌ์šฉ โ€” ๋ฒค๋”๋ณ„ ๋ฌธ๋ฒ• ์ฐจ์ด๊ฐ€ ํฌ๋ฏ€๋กœ ์‚ฌ์šฉ ์ค‘์ธ DB๋ฅผ ๋จผ์ € ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” SQL AUTO INCREMENT Field โ€” https://www.w3schools.com/sql/sql_autoincrement.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL AUTO INCREMENT Field" page (Astra wiki-curation, P-Reinforce v3.1 format).