Lesson 8 of 30
27%
CREATE TABLE
CREATE TABLE draws the grid: column names and types.
No rows yet. You only built the empty lockers.
A first table
Each column has a name and a type.
Commas sit between columns. The last column has no comma.
sql
Result
Query OK, 0 rows affected
Not null and defaults
NOT NULL means the cell cannot be empty.
DEFAULT fills a value if you skip that column on insert.
sql
Result
Query OK, 0 rows affected
See your work
sql
Result
| Tables_in_fox_school |
|---|
| students |
1 row
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | int | NO | NULL | ||
| name | varchar(80) | NO | NULL | ||
| age | int | YES | NULL | ||
| city | varchar(60) | YES | Unknown |
4 rows
Drop a table
DROP TABLE removes the grid and the rows.
Use IF EXISTS so a missing name does not error.
sql
Result
Query OK, 0 rows affected
Tip: Plan columns before you type CREATE TABLE. Changing later is possible, but starting clear is easier.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.