--- id: sql-unique title: "SQL Unique" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL UNIQUE Constraint", "UNIQUE constraint"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "unique", "constraints"] raw_sources: ["https://www.w3schools.com/sql/sql_unique.asp"] applied_in: [] github_commit: "" --- # [[SQL Unique]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) UNIQUE guarantees every value in a column is distinct β€” like PRIMARY KEY, but a table can have many UNIQUE constraints versus only one PRIMARY KEY. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **UNIQUE constraint** β€” ensures all values in a column are unique. [S1] - **UNIQUE vs. PRIMARY KEY** β€” both guarantee uniqueness, but a table can have many UNIQUE constraints, and only one PRIMARY KEY. [S1] - **On CREATE TABLE** β€” inline (`ID int NOT NULL UNIQUE`) for SQL Server/Oracle/Access, or a separate `UNIQUE (ID)` clause for MySQL. [S1] - **Named/multi-column UNIQUE** β€” `CONSTRAINT UC_Person UNIQUE (ID, LastName)` names the constraint and spans multiple columns. [S1] - **On ALTER TABLE** β€” `ALTER TABLE Persons ADD UNIQUE (ID);` for an existing table. [S1] - **Dropping** β€” `DROP INDEX UC_Person;` (MySQL) vs. `DROP CONSTRAINT UC_Person;` (SQL Server/Oracle/Access). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **MySQL 문법 차이**: λ‹€λ₯Έ λ²€λ”λŠ” 컬럼 μ˜†μ— 인라인 `UNIQUE` ν‚€μ›Œλ“œλ₯Ό μ“°μ§€λ§Œ, MySQL은 λ³„λ„μ˜ `UNIQUE (ID)` 절이 ν•„μš”ν•¨. λ“œλ‘­ μ‹œμ—λ„ MySQL은 `DROP INDEX`, λ‚˜λ¨Έμ§€λŠ” `DROP CONSTRAINT`둜 κ°ˆλ¦°λ‹€. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - SQL Server/Oracle/Access inline: `CREATE TABLE Persons (ID int NOT NULL UNIQUE, ...);`. [S1] - MySQL: `CREATE TABLE Persons (ID int NOT NULL, ..., UNIQUE (ID));`. [S1] - Named multi-column constraint: `CONSTRAINT UC_Person UNIQUE (ID,LastName)`. [S1] - Add to existing table: `ALTER TABLE Persons ADD UNIQUE (ID);`. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” PRIMARY KEYκ°€ 이미 μžˆλŠ” 컬럼 외에 "κ³ μœ ν•΄μ•Ό ν•˜μ§€λ§Œ λŒ€ν‘œν‚€λŠ” μ•„λ‹Œ" 컬럼(예: 이메일, 주민번호)에 ν”νžˆ 쓰인닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Named multi-column UNIQUE (SQL): ```sql CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, CONSTRAINT UC_Person UNIQUE (ID,LastName) ); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Constraints]], [[SQL Primary Key]], [[SQL Not Null]] - **μ°Έμ‘° λ§₯락:** λŒ€ν‘œν‚€λŠ” μ•„λ‹ˆμ§€λ§Œ κ°’μ˜ κ³ μœ μ„±μ„ 보μž₯ν•΄μ•Ό ν•˜λŠ” μ»¬λŸΌμ— μ‚¬μš©. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL UNIQUE Constraint β€” https://www.w3schools.com/sql/sql_unique.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL UNIQUE Constraint" page (Astra wiki-curation, P-Reinforce v3.1 format).