SQLMarrow / Course Academy Experience

SQL & Databases Masterclass Course

Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!

COURSE PROGRESS
0%
0 of 40 Modules Solved
COURSE SYLLABUS
40 Lessons
LESSON WORKSPACEAdvanced

SQL Lesson 16: Creating tables

Introduction & Core Concept

We now enter Data Definition Language (DDL). To construct brand new table schemas inside a relational database, we write a CREATE TABLE statement defining the primary key, column headers, and structural datatypes.

CREATE TABLE table_name (
  id INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  balance REAL DEFAULT 0.0,
  join_date DATE
);
Core Structural Datatypes
  • INTEGER: Whole numeric numbers without decimals.
  • TEXT (or VARCHAR): Character sequences and text strings.
  • REAL (or DECIMAL / FLOAT): Floating-point decimal numbers.
  • DATE / DATETIME: Calendar timestamps.
  • Why & Where We Use It
  • Why We Use It: Enforces strict structural integrity. Unlike NoSQL document stores where any arbitrary data can be inserted, SQL tables enforce strict schema rules preventing corrupt or malformed data from entering the system.
  • Where We Use It: Initializing application databases, creating temporary audit logging tables, and standing up data warehouse reporting staging tables.
  • Real-World Example

    ShopMart wants to build a new customer support ticketing module. The database architect writes a CREATE TABLE support_tickets query specifying an auto-incrementing ticket ID, customer ID linking key, issue details text block, and a default status of 'Open'.

    Best Practices: What to Do & What NOT to Do
  • What to Do: Always include IF NOT EXISTS in your creation statements (e.g., CREATE TABLE IF NOT EXISTS my_table). This prevents script crash errors if the table was already created during an earlier deployment.
  • What NOT to Do: Do not omit Primary Keys. Every robust relational table should possess a dedicated primary key to ensure row uniqueness and enable high-speed index lookups.
  • Syntax & Pro Tips
    CREATE TABLE IF NOT EXISTS audit_logs (
      log_id INTEGER PRIMARY KEY AUTOINCREMENT,
      action TEXT NOT NULL,
      created_at DATETIME DEFAULT CURRENT_TIMESTAMP
    );
    Interactive Sandboxed Terminal (Preloaded DB Schema: SHOPMART)
    SQL Query WorkspaceSQLite v3.45 (WASM Mode)
    QUICK INSERT:
    1