Before you can query anything, you need a database to hold it and a table shaped to fit your data. This lesson covers the handful of commands you'll run before writing a single SELECT.
Creates a new, empty database on the server.
CREATE DATABASE database_name;CREATE DATABASE CompanyDB;USE.Common Mistake
Creating a database with the same name as an existing one without checking first.
Switches the active database for the current session.
USE database_name;USE CompanyDB;All statements that follow run against this database until you switch again.
Common Mistake
Running a query against the wrong database because USE was never called first.
Lists the databases on the server, or the tables inside the current one.
SHOW DATABASES;
SHOW TABLES;| Tables_in_CompanyDB |
|---|
| Employee |
| Department |
A quick way to see what already exists before writing a query against it.
Common Mistake
Assuming SHOW TABLES works identically across every database engine — the exact syntax varies between MySQL, PostgreSQL, and others.
Every column is given a type that constrains what it can store and how much room it takes.
With a database and the idea of typed columns in place, the next lesson goes deep on choosing the right type and size for every column you'll ever define.