Choose a practice tool
You learn SQL by typing queries and seeing results. Pick one of these free options. All of them run the queries in this course.
| Option | Good for | Notes |
|---|
| Online SQL playground | Starting immediately, cyber café, any device | Search for "SQLite online" or "SQL playground". Data may be lost when you close the tab, so keep your script saved |
| DB Browser for SQLite | Low-cost laptops, offline practice | Free desktop app for Windows, macOS and Linux. The database is a single .db file |
| MySQL Community Server + MySQL Workbench | Learning the database used by many Indian companies and websites | Larger install; you create a username and password during setup |
If you are unsure, start with DB Browser for SQLite. It is small, works offline and has no server to manage. Download it only from its official website, sqlitebrowser.org.
Creating the shop database in DB Browser for SQLite
- Open DB Browser and click New Database. Save the file as
shop.db in a folder you can find, such as Documents. - If a "create table" window opens, close it. We will create tables with SQL instead.
- Open the Execute SQL tab. This is where you type queries.
- Paste the full script below and click the Execute button (the play icon), or press Ctrl + Enter.
- Click Write Changes (or press Ctrl + S) so the data is saved to the file.
In MySQL Workbench, first run CREATE DATABASE shop; and USE shop;, then run the same script.
The setup script
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
city VARCHAR(30),
phone VARCHAR(15),
joined_on DATE
);
CREATE TABLE products (
product_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
category VARCHAR(30),
price INT
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
product_id INT,
quantity INT,
order_date DATE,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);
INSERT INTO customers VALUES
(1, 'Asha Verma', 'Jaipur', '9800000001', '2025-11-10'),
(2, 'Rohit Sharma', 'Lucknow', NULL, '2025-12-02'),
(3, 'Imran Khan', 'Jaipur', '9800000003', '2025-12-15'),
(4, 'Neha Gupta', 'Indore', '9800000004', '2026-01-04'),
(5, 'Priya Nair', 'Kochi', NULL, '2026-01-20'),
(6, 'Vikram Singh', 'Lucknow', '9800000006', '2026-02-11');
INSERT INTO products VALUES
(101, 'Notebook', 'Stationery', 60),
(102, 'Pen Pack', 'Stationery', 50),
(103, 'Pen Drive 32 GB', 'Electronics', 450),
(104, 'Wireless Mouse', 'Electronics', 599),
(105, 'Water Bottle', 'Home', 250),
(106, 'Desk Lamp', 'Home', 899);
INSERT INTO orders VALUES
(1, 1, 101, 5, '2026-01-05'),
(2, 1, 103, 1, '2026-01-12'),
(3, 2, 104, 1, '2026-01-20'),
(4, 3, 102, 4, '2026-02-03'),
(5, 3, 101, 10, '2026-02-03'),
(6, 4, 105, 2, '2026-02-14'),
(7, 2, 103, 2, '2026-03-01'),
(8, 5, 104, 1, '2026-03-08'),
(9, 1, 105, 1, '2026-03-15'),
(10, 4, 102, 2, '2026-03-22');
Understanding the script
CREATE TABLE defines a table, its columns and each column's data type.INT stores whole numbers. VARCHAR(50) stores text up to 50 characters. DATE stores a date written as 'YYYY-MM-DD'.PRIMARY KEY makes the column unique for every row.NOT NULL means the value cannot be left empty: every customer must have a name.FOREIGN KEY ... REFERENCES records the link from orders to the other two tables.INSERT INTO ... VALUES adds rows. Text and dates go inside single quotes; numbers do not.- Each statement ends with a semicolon
;.
Prices are stored as whole rupees with INT to keep the results identical in every database. Real systems often use DECIMAL(10,2) for money so that paise are stored exactly.
Check that it worked
Run this query:
SELECT COUNT(*) FROM orders;
You should see 10. Try the same with customers (6) and products (6). If you get an error such as "table already exists", you ran the script twice. That is harmless for practice: create a fresh database file and run it once.
SQL writing habits
- SQL keywords are not case-sensitive.
select works like SELECT, but writing keywords in capitals makes queries easier to read. - Spaces and line breaks do not matter. Put each clause on its own line.
- A line starting with
-- is a comment that SQL ignores. Use comments to note what a query does. - Save your queries in a text file (for example
practice.sql) so you can reuse them.
Common mistakes
- Using double quotes or curly "smart" quotes copied from a word processor around text. Use plain single quotes:
'Jaipur'. - Forgetting the comma between columns or between rows of
VALUES. - Closing DB Browser without clicking Write Changes, which loses your new data.
Practice task
- Create
shop.db and run the setup script. - Confirm the row counts: 6 customers, 6 products, 10 orders.
- Add a comment line at the top of your script, such as
-- Shop practice database, and save the script as shop_setup.sql. - Open the Browse Data tab (or run
SELECT * FROM products;) and check that the prices match the tables in Lesson 1.