PostgreSQL Sample Database
A sample database is useful for testing queries, learning SQL, and developing applications. Below, you'll find a step-by-step guide to creating and loading a sample PostgreSQL database.
1. Download & Install PostgreSQL
If you haven’t installed PostgreSQL yet, download it from:
🔗 https://www.postgresql.org/download/
Verify Installation
After installing, check the version:
2. Create a New Database
To create a sample database, open psql
or pgAdmin and run:
Switch to the new database:
3. Create Sample Tables
customers
Table
products
Table
orders
Table
order_items
Table
4. Insert Sample Data
Customers
Products
Orders
Order Items
5. Query Sample Data
View All Customers
Get Orders with Customer Details
Check Product Stock
Find Top Customers by Spending
6. Export and Import Sample Database
Export Database
To export the database as a backup file:
Import Database
To restore from a backup file:
7. Summary
Action | Command |
---|---|
Create Database | CREATE DATABASE sampledb; |
Create Table | CREATE TABLE customers (...); |
Insert Data | INSERT INTO customers (...) VALUES (...); |
View Data | SELECT * FROM customers; |
Export Database | pg_dump -U postgres -d sampledb -f sampledb.sql |
Import Database | psql -U postgres -d sampledb -f sampledb.sql |
Would you like a sample database with more data for testing? 🚀