Meet ShopKart
ShopKart is a small online shop. It sells headphones, smartwatches and phone accessories to customers across India. Every sign-up, order and product lives in a database. Throughout this course, you'll answer real questions about ShopKart with SQL: “Who are our best customers?”, “Which products never sell?”, “How did revenue change from April to May?”.
Tables, rows and columns
A table is like a spreadsheet with strict rules. Each row is one thing (one customer). Each column is one fact about it (name, city), and every value in a column has the same type (text, number, date).
SELECT * FROM customers;| customer_id | name | city | signup_date |
|---|---|---|---|
| 1 | Asha | Kolkata | 2026-01-05 |
| 2 | Rahul | Mumbai | 2026-01-20 |
| 3 | Priya | Bengaluru | 2026-02-03 |
| 4 | Imran | Delhi | 2026-02-14 |
| 5 | Meera | Chennai | 2026-03-01 |
| 6 | Arjun | Kolkata | 2026-03-18 |
| 7 | Sara | Mumbai | 2026-04-02 |
| 8 | Vikram | NULL | 2026-04-10 |
SELECT * means “all columns”. Notice Vikram's city is NULL: the value is unknown. NULLs cause many beginner bugs; lesson 2 shows how to handle them.
Keys: how tables connect
- Primary key (PK): a column that uniquely identifies each row, never empty.
customer_idin customers. - Foreign key (FK): a column that points to a primary key in another table.
orders.customer_idsays which customer placed the order. The database refuses an order for a customer that doesn't exist.
Who buys
customers
PK customer_id
- name
- city
- signup_date
logins
FK customer_id
- login_date
What they buy
orders
PK order_id · FK customer_id
- order_date
- status
order_items
PK (order_id, product_id)
- quantity
- unit_price
products
PK product_id
- name
- category
- price
Who works here
employees
PK emp_id · FK manager_id → emp_id
- name
- department
- salary
One customer has many orders (one-to-many). One order has many items, and one product appears in many orders, so order_items sits between them (many-to-many). This is how almost every real database is shaped.
How ShopKart was created
This is the exact script we used. Don't worry about every word yet; lesson 7 explains CREATE TABLE and constraints.
-- ShopKart: a small online shop's database
CREATE TABLE customers (
customer_id INT PRIMARY KEY,
name TEXT NOT NULL,
city TEXT, -- can be unknown (NULL)
signup_date DATE NOT NULL
);
CREATE TABLE products (
product_id INT PRIMARY KEY,
name TEXT NOT NULL,
category TEXT NOT NULL,
price NUMERIC(10, 2) NOT NULL CHECK (price > 0)
);
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL REFERENCES customers (customer_id),
order_date DATE NOT NULL,
status TEXT NOT NULL -- PLACED, DELIVERED, CANCELLED, RETURNED
);
CREATE TABLE order_items (
order_id INT REFERENCES orders (order_id),
product_id INT REFERENCES products (product_id),
quantity INT NOT NULL CHECK (quantity > 0),
unit_price NUMERIC(10, 2) NOT NULL,
PRIMARY KEY (order_id, product_id)
);
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name TEXT NOT NULL,
manager_id INT REFERENCES employees (emp_id),
department TEXT NOT NULL,
salary INT NOT NULL
);
CREATE TABLE logins (
customer_id INT REFERENCES customers (customer_id),
login_date DATE NOT NULL
);# create a database and load ShopKart (after installing PostgreSQL)$createdb shopkart$psql -d shopkart -f shopkart-setup.sql# open an interactive SQL prompt$psql -d shopkart
Your first real query
SELECT name, city
FROM customers;| name | city |
|---|---|
| Asha | Kolkata |
| Rahul | Mumbai |
| Priya | Bengaluru |
| Imran | Delhi |
| Meera | Chennai |
| Arjun | Kolkata |
| Sara | Mumbai |
| Vikram | NULL |
SELECT lists the columns you want, FROM names the table. SQL keywords aren't case-sensitive (select works too), but writing them in capitals makes queries easier to read. End each statement with ;.
The five kinds of SQL commands
| Group | Stands for | Commands | Does |
|---|---|---|---|
| DQL | Data Query Language | SELECT | Reads data |
| DML | Data Manipulation Language | INSERT, UPDATE, DELETE, MERGE | Changes rows |
| DDL | Data Definition Language | CREATE, ALTER, DROP, TRUNCATE | Changes structure |
| DCL | Data Control Language | GRANT, REVOKE | Permissions |
| TCL | Transaction Control Language | BEGIN, COMMIT, ROLLBACK | Groups changes safely |
SQL everywhere
| Where | Example | Same SQL? |
|---|---|---|
| App databases (OLTP) | PostgreSQL, MySQL, SQL Server, Oracle | Yes, small dialect differences |
| Cloud warehouses | Snowflake, BigQuery, Redshift | Yes, plus extras like QUALIFY |
| Lakehouse | Databricks SQL, Spark SQL | Yes (see our Databricks course) |
| Transformation tools | dbt | SQL files turned into pipelines |
🎯 Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1What is the difference between a primary key and a foreign key?Fresher
Q2DELETE vs TRUNCATE vs DROP?Fresher
Q3What is a relational database?Fresher
Q4What is a composite key? Give an example.1–3 yrs
Q5Can a foreign key be NULL?1–3 yrs
Key takeaways
- SQL is how you ask a database questions; it's the core skill of every data job.
- Tables connect through primary and foreign keys.
- ShopKart has customers, orders, order_items, products, employees and logins.
- Next: filtering rows with WHERE, and the NULL trap.
Frequently asked questions
What is SQL in simple words?
SQL (Structured Query Language) is the language you use to ask a database questions and change its data. You describe what you want, such as 'customers in Kolkata', and the database works out how to find it.
Is SQL a programming language?
It's a declarative query language: you say what result you want, not the step-by-step how. It isn't used to build apps on its own, but it's the most important language for working with data.
Which SQL should I learn: MySQL, PostgreSQL or SQL Server?
Learn standard SQL with any of them; 90% is identical. This course uses PostgreSQL because it's free, popular and close to the standard. Databricks SQL and Snowflake work almost the same way.
How long does it take to learn SQL?
The basics (SELECT, WHERE, GROUP BY, JOIN) take a few days of practice. Interview-level SQL (window functions, CTEs, modelling) takes a few weeks of solving problems.
Why do data engineers need SQL?
Almost every data tool speaks SQL: warehouses, Databricks, Snowflake, dbt, BI tools. Data engineers use it to explore data, build pipeline transformations, test data quality and serve analysts.
🧠 Quick check: what is SQL?
1. What uniquely identifies each row in a table?
2. orders.customer_id points to customers.customer_id. It's a...
3. SELECT belongs to which group of commands?
4. CREATE TABLE is...