Skip to content
Learn Netverks

Lesson

Step 12/36 33% through track

create-table-mysql

CREATE TABLE in MySQL

Last reviewed Jun 1, 2026 Content v20260601
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~1 min
Level
beginner

This lesson

This lesson teaches CREATE TABLE in MySQL: the SQL patterns, schema habits, and query reasoning you need before advancing in MySQL.

Teams query CREATE TABLE in MySQL on every MySQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply CREATE TABLE in MySQL in contexts like: Web apps on shared hosting, ecommerce, and many startups’ first production DB.

Copy MySQL SQL into the mysql client, local MySQL/MariaDB, or DB Fiddle (MySQL dialect)—use DESCRIBE and EXPLAIN where lessons show them. The in-browser lab ships later; mysql client is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

DDL with engine clause, defaults, and IF NOT EXISTS. Prefer explicit types and NOT NULL where business rules require values.

Table definition

CREATE TABLE IF NOT EXISTS orders (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  customer_id BIGINT UNSIGNED NOT NULL,
  status ENUM('open','paid','shipped') NOT NULL DEFAULT 'open',
  total DECIMAL(12,2) NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Practice: Run on practice.

ALTER preview

ALTER TABLE orders ADD COLUMN notes TEXT NULL AFTER status;
ALTER TABLE orders MODIFY COLUMN notes VARCHAR(500) NULL;

ENUM caution

ENUM is convenient but awkward to evolve—VARCHAR + app validation or lookup table for volatile sets.

Important interview questions and answers

  1. Q: ENGINE=InnoDB?
    A: Transactional storage with row locks and FK support.
  2. Q: CURRENT_TIMESTAMP?
    A: Default for created_at on insert—ON UPDATE for updated_at patterns.

Self-check

  1. Why ENGINE=InnoDB?
  2. When is ENUM risky?

Tip: Prefer TIMESTAMP/DATETIME defaults for audit columns.

Interview prep

ENGINE=InnoDB?

Transactional storage with FK support.

ENUM risk?

Hard to change allowed values in large tables.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • ENUM risk?
  • ENGINE clause?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump