Sales design
- SQL course
- Intermediate
- Lesson 42/115
- 5 min
Set up the sales tables and write skeleton queries.
Sales design
In this project you will build a sales report database. First step: create the sales table.
CREATE TABLE sales (
id INT PRIMARY KEY,
product VARCHAR(50),
amount DECIMAL(10,2),
sale_date DATE
);Skeleton of the sales table.
The table sales is created.
Sales design — details
DECIMAL(10,2) means ten total digits, two after the decimal. Good for monetary amounts.
The sales table holds each sale's date (sale_date DATE), product, customer and amount (amount DECIMAL(10,2)).
Practice Sales design
Create sales with id, product, amount and sale_date.
Starter code
-- sales table
CREATE TABLE salesSample solution
CREATE TABLE sales (
id INT PRIMARY KEY,
product VARCHAR(50),
amount DECIMAL(10,2),
sale_date DATE
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 How many decimals in DECIMAL(10,2)?
- Two Correct answer
- Ten
- None
- Five
Explanation: DECIMAL(10,2) gives two decimal places.
2 Add PRIMARY KEY
CREATE TABLE sales (
id INT ____,
product VARCHAR(50)
);
CREATE TABLE sales (
id INT PRIMARY KEY,
product VARCHAR(50)
);
Explanation: PRIMARY KEY is the right answer.
3 Sales design: match the terms
| Term | Meaning |
|---|---|
id |
primary key |
amount |
amount |
sale_date |
date |
DECIMAL |
decimal |