-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastapi_db.sql
More file actions
39 lines (33 loc) · 951 Bytes
/
Copy pathfastapi_db.sql
File metadata and controls
39 lines (33 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- FastAPI Machine Test SQL Script
-- Deliverable 2: MySQL schema + sample data
-- 1) Create Database
CREATE DATABASE IF NOT EXISTS fastapi_db;
-- 2) Use Database
USE fastapi_db;
-- 3) Create Tables
CREATE TABLE IF NOT EXISTS categories (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL
);
CREATE TABLE IF NOT EXISTS products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(150) NOT NULL,
price INT NOT NULL,
category_id INT NOT NULL,
CONSTRAINT fk_products_category
FOREIGN KEY (category_id)
REFERENCES categories(id)
ON DELETE CASCADE
ON UPDATE CASCADE
);
-- 5) Insert Sample Data (3+ categories, 5+ products)
INSERT INTO categories (name) VALUES
('Electronics'),
('Fashion'),
('Books');
INSERT INTO products (name, price, category_id) VALUES
('Laptop', 55000, 1),
('Smartphone', 25000, 1),
('Headphones', 3000, 1),
('T-Shirt', 800, 2),
('Python Handbook', 1200, 3);