--- id: sql-default title: "SQL Default" category: "Database" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["SQL DEFAULT Constraint", "DEFAULT constraint"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.88 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["sql", "database", "w3schools", "default", "constraints"] raw_sources: ["https://www.w3schools.com/sql/sql_default.asp"] applied_in: [] github_commit: "" --- # [[SQL Default]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) DEFAULT auto-fills a column with a fallback value when none is provided, and can hold a system function call (like the current date) instead of a static literal. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **DEFAULT constraint** β€” automatically inserts a default value for a column if no value is specified; applies to all new records. [S1] - **On CREATE TABLE** β€” e.g. `City varchar(255) DEFAULT 'Sandnes'`. [S1] - **System-value defaults** β€” functions like `CURRENT_DATE()` (MySQL) or `CAST(GETDATE() AS date)` (SQL Server) auto-populate the current date. [S1] - **On ALTER TABLE** β€” vendor-specific syntax to add or drop a DEFAULT after table creation (MySQL, SQL Server, MS Access, Oracle all differ). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **4개 벀더 λͺ¨λ‘ λ‹€λ₯Έ ALTER 문법**: DEFAULTλ₯Ό λ‚˜μ€‘μ— μΆ”κ°€/μ œκ±°ν•˜λŠ” 문법이 MySQL(`ALTER ... SET DEFAULT`/`DROP DEFAULT`), SQL Server(`ADD CONSTRAINT ... DEFAULT ... FOR col`), MS Access(`ALTER COLUMN ... SET DEFAULT`), Oracle(`MODIFY col DEFAULT ...`)μ—μ„œ 각각 닀름. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Static default on creation: `City varchar(255) DEFAULT 'Sandnes'` inside CREATE TABLE. [S1] - System-value default (MySQL): `OrderDate date DEFAULT CURRENT_DATE()`. [S1] - System-value default (SQL Server): `OrderDate date DEFAULT CAST(GETDATE() AS date)`. [S1] - Add after creation (MySQL): `ALTER TABLE Persons ALTER City SET DEFAULT 'Sandnes';`. [S1] - Add after creation (SQL Server): `ALTER TABLE Persons ADD CONSTRAINT df_City DEFAULT 'Sandnes' FOR City;`. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” 값이 λΉ„μ–΄μžˆμ„ λ•Œ 정적 κΈ°λ³Έκ°’ λ˜λŠ” ν˜„μž¬ λ‚ μ§œ 같은 μ‹œμŠ€ν…œ 값을 μžλ™ μ±„μš°λŠ” 데 쓰인닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Static and system-value defaults (SQL): ```sql CREATE TABLE Persons ( ID int PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, City varchar(255) DEFAULT 'Sandnes' ); -- MySQL system default CREATE TABLE Orders ( ID int PRIMARY KEY, OrderNumber int NOT NULL, OrderDate date DEFAULT CURRENT_DATE() ); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.88 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[SQL Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[SQL Constraints]], [[SQL Check]], [[SQL Dates]] - **μ°Έμ‘° λ§₯락:** 값이 λͺ…μ‹œλ˜μ§€ μ•Šμ€ μ»¬λŸΌμ„ μžλ™μœΌλ‘œ μ±„μ›Œμ•Ό ν•  λ•Œ μ‚¬μš©. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” SQL DEFAULT Constraint β€” https://www.w3schools.com/sql/sql_default.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "SQL DEFAULT Constraint" page (Astra wiki-curation, P-Reinforce v3.1 format).