Databases and Tables
A database holds tables. A table holds rows.
You pick a database with USE, then you work on its tables.
See what exists
SHOW DATABASES lists every database the server knows.
SHOW TABLES lists tables in the one you picked.
| Database |
|---|
| information_schema |
| fox_school |
| mysql |
3 rows
Database changed
| Tables_in_fox_school |
|---|
| scores |
| students |
2 rows
Describe a table
DESCRIBE tells you column names and types.
That is like reading the labels on the drawers before you open them.
| Field | Type | Null | Key | Default | Extra |
|---|---|---|---|---|---|
| id | int | NO | PRI | NULL | auto_increment |
| name | varchar(80) | NO | NULL | ||
| age | int | YES | NULL | ||
| city | varchar(60) | YES | Unknown |
4 rows
Naming ideas
Use a short database name for the project.
Use plural table names: students, orders, foxes.
Use snake_case columns: first_name, created_at.
One idea per table
Clear names beat clever names
Avoid spaces in names
A mental picture
fox_school is the building.
students is a room of lockers.
Each locker is a row. Each shelf label is a column.
Tip: Always USE the right database before CREATE TABLE, or the table lands in the wrong box.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.