--- id: php-mysql-create-table title: "PHP MySQL Create Table" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["CREATE TABLE", "AUTO_INCREMENT", "PHP MySQL 테이블 생성"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.89 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "mysql", "create-table"] raw_sources: ["https://www.w3schools.com/php/php_mysql_create_table.asp"] applied_in: [] github_commit: "" --- # [[PHP MySQL Create Table]] ## 🎯 한 줄 통찰 (One-line insight) The `reg_date` column's default value (`DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`) does double duty — it auto-fills on INSERT and auto-refreshes on every UPDATE, meaning a single column definition handles both "record creation time" and "last modified time" without any PHP-side logic. [S1] ## 🧠 핵심 개념 (Core concepts) - **`CREATE TABLE`** — the SQL command; this chapter creates "MyGuests" with 5 columns. [S1] - **Column attributes** — `UNSIGNED` (positive numbers + zero only), `AUTO_INCREMENT` (auto-increases by 1 per new record), `PRIMARY KEY` (uniquely identifies rows, often paired with AUTO_INCREMENT), `NOT NULL` (value required), `DEFAULT value` (fallback when none is provided). [S1] - **Every table needs a primary key** — a unique-per-record identifier column. [S1] - **Requires create privileges** — a separate permission from admin privileges (used for CREATE DATABASE). [S1] ## 📖 세부 내용 (Details) - Full table definition: `CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP )`. [S1] - Executed via MySQLi OOP: `$conn->query($sql)`; procedural: `mysqli_query($conn, $sql)`; PDO: `$conn->exec($sql)` inside try/catch. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) 소스에서 모순되는 정보는 발견되지 않음. ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — reg_date 컬럼이 생성 시각과 수정 시각을 동시에 자동 관리하는 것이 실전 스키마 설계의 대표 사례다. [S1] ## 💻 코드 패턴 (Code patterns) Column with dual-purpose auto-updating timestamp (SQL): ```sql CREATE TABLE MyGuests ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.89 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[PHP Tutorial]] - **관련 개념:** [[PHP MySQL Create DB]], [[PHP MySQL Insert]], [[SQL Create Table]] - **참조 맥락:** 테이블 스키마 정의 — 데이터 삽입(Insert) 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — PHP MySQL Create Table — https://www.w3schools.com/php/php_mysql_create_table.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP MySQL Create Table" page (Astra wiki-curation, P-Reinforce v3.1 format).