0Pricing
SQL Academy · Lesson

Seeding the Database with Test Data

Generate realistic test data with INSERT ... SELECT and generate_series, and verify with simple analytical queries.

Why Seed?

Empty databases hide bugs. You want realistic data:

  • To run UI/E2E tests
  • To verify performance characteristics (indexes, query plans)
  • To demo the app

Hand-Written Seeds

For a handful of "fixture" rows, write them by hand in SQL or a migration:

INSERT INTO users (id, email, full_name) VALUES
  (1, 'alice@example.com', 'Alice Adams'),
  (2, 'bob@example.com',   'Bob Brown');

SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));

All lessons in this course

  1. Modelling a Blog: Users Posts Comments
  2. Choosing Keys and Types
  3. Indexes for Common Queries
  4. Seeding the Database with Test Data
← Back to SQL Academy