forked from data-bootcamp-v4/lab-sql-mysql-db-creation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
49 lines (43 loc) · 1.29 KB
/
Copy pathcreate.sql
File metadata and controls
49 lines (43 loc) · 1.29 KB
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
40
41
42
43
44
45
46
47
48
49
CREATE DATABASE IF NOT EXISTS lab_mysql;
USE lab_mysql;
DROP TABLE IF EXISTS invoices;
DROP TABLE IF EXISTS salespersons;
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS cars;
CREATE TABLE cars (
id INT AUTO_INCREMENT PRIMARY KEY,
vin VARCHAR(50) NOT NULL,
manufacturer VARCHAR(50) NOT NULL,
model VARCHAR(50) NOT NULL,
car_year YEAR NOT NULL,
color VARCHAR(30) NOT NULL
);
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
cust_id INT NOT NULL UNIQUE,
cust_name VARCHAR(100) NOT NULL,
cust_phone VARCHAR(30),
cust_email VARCHAR(255),
cust_address VARCHAR(255),
cust_city VARCHAR(100),
cust_state VARCHAR(100),
cust_country VARCHAR(100),
cust_zipcode VARCHAR(20)
);
CREATE TABLE salespersons (
id INT AUTO_INCREMENT PRIMARY KEY,
staff_id VARCHAR(5) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
store VARCHAR(100) NOT NULL
);
CREATE TABLE invoices (
id INT AUTO_INCREMENT PRIMARY KEY,
invoice_number VARCHAR(20) NOT NULL UNIQUE,
invoice_date DATE NOT NULL,
car_id INT NOT NULL,
customer_id INT NOT NULL,
salesperson_id INT NOT NULL,
FOREIGN KEY (car_id) REFERENCES cars(id),
FOREIGN KEY (customer_id) REFERENCES customers(id),
FOREIGN KEY (salesperson_id) REFERENCES salespersons(id)
);