Lab 02: Creating Databases and Tables
Overview
Step 1: Start the Databases
# MySQL
docker run -d --name mysql-lab -e MYSQL_ROOT_PASSWORD=rootpass mysql:8.0
for i in $(seq 1 30); do docker exec mysql-lab mysql -uroot -prootpass -e "SELECT 1" 2>/dev/null && break || sleep 2; done
# PostgreSQL
docker run -d --name pg-lab -e POSTGRES_PASSWORD=rootpass postgres:15
sleep 10Step 2: CREATE DATABASE
CREATE DATABASE IF NOT EXISTS school;
USE school;
SELECT DATABASE();Step 3: Data Types Reference
Category
MySQL
PostgreSQL
Notes
Step 4: CREATE TABLE with Constraints
Step 5: NULL vs NOT NULL vs DEFAULT
Column
INSERT with no value
INSERT NULL
Step 6: DESCRIBE / \d — Inspect Table Structure
Step 7: CREATE TABLE with Multiple Tables and Relationships
Step 8: Capstone — DROP and Recreate
Summary
Command
MySQL
PostgreSQL
Last updated
