Lesson 7 of 30
23%
CREATE DATABASE
CREATE DATABASE makes a new empty box.
Nothing is in it yet. You add tables next.
Make one
Use letters, numbers, and underscores. Skip spaces.
sql
Result
Query OK, 0 rows affected
| Database |
|---|
| fox_school |
| information_schema |
| mysql |
3 rows
Use it
Creating is not the same as selecting.
USE points your session at that database.
sql
Result
Database changed
| DATABASE() |
|---|
| fox_school |
1 row
Safe create
IF NOT EXISTS skips the error if the name is already taken.
sql
Result
Query OK, 0 rows affected, 1 warning (database already exists)
Throw it away
DROP DATABASE deletes the box and every table in it.
There is no undo. Practice on toy data only.
sql
Result
Not run. Uncomment DROP DATABASE only on toy data.
Tip: On shared servers, you may not have permission to CREATE DATABASE. Use the one your host gave you.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.