Cart design
- SQL course
- Beginner
- Lesson 42/115
- 5 min
Set up the shopping cart tables and write skeleton queries.
Cart table
In this project you will build a shopping cart table. The cart table holds customer and product info.
CREATE TABLE cart (
id INT PRIMARY KEY,
customer_id INT,
product_id INT,
qty INT
);Id is the primary key; customer, product and quantity columns.
The table cart is created.
Cart table — details
The cart table stores how many of each product a customer wants. Each row is one cart line.
Practice Cart table
Create cart with id INT PRIMARY KEY, customer_id INT, product_id INT, qty INT.
Starter code
-- cart table
CREATE TABLE cartSample solution
CREATE TABLE cart (
id INT PRIMARY KEY,
customer_id INT,
product_id INT,
qty INT
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the cart table hold?
- Customer and product information Correct answer
- Only the price
- Only the date
- Only the name
Explanation: Cart holds customer, product and quantity.
2 Create table
CREATE ____ cart (id INT PRIMARY KEY, qty INT);
CREATE TABLE cart (id INT PRIMARY KEY, qty INT);
Explanation: The cart table is created with CREATE TABLE.
3 Cart design: match the terms
| Term | Meaning |
|---|---|
CREATE TABLE |
create table |
INSERT |
insert |
SELECT |
read |
DELETE |
delete |