DDL & Data Types in SQL

From the SQL cheat sheet ยท Table Management ยท verified Jul 2026

DDL & Data Types

Define tables with CREATE, ALTER, DROP and choose the right data types.

sql
-- CREATE TABLE
CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255) UNIQUE,
  age INT CHECK (age >= 0),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- ALTER TABLE
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
ALTER TABLE users DROP COLUMN phone;
ALTER TABLE users RENAME COLUMN name TO full_name;

-- DROP TABLE
DROP TABLE IF EXISTS temp_data;
๐Ÿ’ก Auto-increment syntax varies: AUTO_INCREMENT (MySQL), SERIAL (PG), IDENTITY (SQL Server)
โšก Use DECIMAL(10,2) for money โ€” never use FLOAT for financial data
๐Ÿ“Œ VARCHAR(255) is a safe default for most string columns; use TEXT for unlimited length
๐ŸŸข Always use DROP TABLE IF EXISTS to avoid errors in scripts and migrations
ddlcreate-tabledata-typesalter
Back to the full SQL cheat sheet