1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
3.6 KiB
3.6 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| sql-foreign-key | SQL Foreign Key | Database | draft | conceptual |
|
B | 0.9 | 2026-07-04 | 2026-07-04 |
|
|
SQL Foreign Key
🎯 한 줄 통찰 (One-line insight)
FOREIGN KEY links a child table's column to a parent table's PRIMARY KEY, blocking both invalid inserts into the child and deletes from the parent that would orphan child rows. [S1]
🧠 핵심 개념 (Core concepts)
- FOREIGN KEY constraint — establishes a link between two tables and prevents actions that would destroy that link. [S1]
- Child vs. parent table — the table holding the foreign key column is the child table; the table holding the referenced primary key is the parent (referenced) table. [S1]
- Two-way protection — blocks invalid inserts into the child (value must exist in the parent), and blocks deletes from the parent that would orphan matching child rows. [S1]
- Syntax (on create) —
CONSTRAINT fk_Person FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)insideCREATE TABLE. [S1] - Syntax (on alter) —
ALTER TABLE Orders ADD CONSTRAINT fk_Person FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);. [S1]
📖 세부 내용 (Details)
- Define on table creation: [S1]
CREATE TABLE Orders (
OrderID int PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int,
CONSTRAINT fk_Person
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
- Add to an existing table:
ALTER TABLE Orders ADD CONSTRAINT fk_Person FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);. [S1] - Drop:
ALTER TABLE Orders DROP CONSTRAINT fk_Person;(SQL Server/Oracle/Access) vs.ALTER TABLE Orders DROP FOREIGN KEY fk_Person;(MySQL). [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
- 드롭 문법 차이: SQL Server/Oracle/Access는
DROP CONSTRAINT, MySQL은DROP FOREIGN KEY를 사용. [S1]
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — DROP TABLE 챕터에서 이미 "FK로 참조되는 테이블은 바로 드롭할 수 없다"는 제약이 선행 언급되었다. [S1]
💻 코드 패턴 (Code patterns)
FOREIGN KEY on table creation (SQL):
CREATE TABLE Orders (
OrderID int PRIMARY KEY,
OrderNumber int NOT NULL,
PersonID int,
CONSTRAINT fk_Person
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
);
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.90
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: SQL Tutorial
- 관련 개념: SQL Primary Key, SQL Drop Table, SQL Inner Join
- 참조 맥락: 테이블 간 참조 무결성을 강제할 때 사용 — JOIN에서 활용되는 관계가 바로 이 제약으로 정의된다.
📚 출처 (Sources)
- [S1] W3Schools — SQL FOREIGN KEY Constraint — https://www.w3schools.com/sql/sql_foreignkey.asp
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "SQL FOREIGN KEY Constraint" page (Astra wiki-curation, P-Reinforce v3.1 format).