SQL Tutorial · Revision notes

SQL Database & Tables (DDL)

DDL commands build and manage the structure of a database. We use CREATE to make a database or table, ALTER to change it, DROP to remove it and constraints to keep the data correct.

Quick revision

  • CREATE DATABASE makes a database. USE selects it.
  • CREATE TABLE needs column name and data type.
  • ALTER TABLE: ADD, MODIFY, RENAME, DROP column.
  • DROP removes table. TRUNCATE empties it. DELETE removes chosen rows.
  • Use DECIMAL for money, VARCHAR for text, DATE for dates.
  • PRIMARY KEY = unique + not null. Only one per table.
  • FOREIGN KEY links to another table. UNIQUE stops duplicates. CHECK tests a condition.
Read the full SQL Database & Tables (DDL) notes on Doubtclip →