Skip to content

Solved Lab #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ER-Diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
CREATE DATABASE IF NOT EXISTS lab_mysql;

USE lab_mysql;

DROP TABLE IF EXISTS Invoices;
DROP TABLE IF EXISTS Salesperson;
DROP TABLE IF EXISTS Customers;
DROP TABLE IF EXISTS Cars;


CREATE TABLE Cars (
id INT AUTO_INCREMENT PRIMARY KEY,
VIN CHAR(20) UNIQUE,
manufacturer VARCHAR(20),
model VARCHAR(20),
year YEAR,
color CHAR(10)
);


CREATE TABLE Customers (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_ID CHAR(5) UNIQUE,
name VARCHAR(40),
phone_number CHAR(20),
email VARCHAR(30),
address VARCHAR(40),
city CHAR(20),
state_province CHAR(20),
country VARCHAR(30),
zip_postal_code CHAR(10)
);



CREATE TABLE Salesperson (
id INT AUTO_INCREMENT PRIMARY KEY,
staff_ID CHAR(5) UNIQUE,
name VARCHAR(40),
store CHAR(20)
);



CREATE TABLE Invoices (
id INT AUTO_INCREMENT PRIMARY KEY,
invoice_number CHAR(10) UNIQUE,
customer_ID CHAR(5),
staff_ID CHAR(5),
VIN CHAR(20),
date DATE,
FOREIGN KEY (customer_ID) REFERENCES Customers(customer_ID),
FOREIGN KEY (staff_ID) REFERENCES Salesperson(staff_ID),
FOREIGN KEY (VIN) REFERENCES Cars(VIN)
);
36 changes: 36 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
INSERT INTO Cars ( VIN, manufacturer, model, year, color)
VALUES ('3K096I98581DHSNUP', 'Volkswagen','Tiguan',2019,'Blue'),
('ZM8G7BEUQZ97IH46V', 'Peugeot','Rifter',2019,'Red'),
('RKXVNNIHLVVZOUB4M','Ford','Fusion',2018,'White'),
('HKNDGS7CU31E9Z7JW','Toyota','RAV4',2018,'Silver'),
('DAM41UDN3CHU2WVF6','Volvo','V60', 2019,'Gray'),
('DAM41UDN3CHU2WVF6','Volvo','V60 Cross Country',2019,'Gray');

INSERT INTO Customers (customer_ID, name, phone_number, email, address, city, state_province, country, zip_postal_code)
VALUES ('10001','Pablo Picasso','+34 636 17 63 82','-','Paseo de la Chopera 14','Madrid','Madrid', 'Spain','28045'),
('20001', 'Abraham Lincoln','+1 305 907 7086','-','120 SW 8th St','Miami','Florida','United States','33130'),
('30001','Napoléon Bonaparte','+33 1 79 75 40 00','-','40 Rue du Colisée','Paris','Île-de-France','France','75008');


INSERT INTO Salesperson (staff_ID, name, store)
VALUES ('00001', "Petey Cruiser", "Madrid"),
('00002',"Anna Sthesia", "Barcelona"),
('00003',"Paul Molive", "Berlin"),
('00004',"Gail Forcewind", "Paris"),
('00005',"Paige Turner","Miami"),
('00006',"Bob Frapples","Mexico City"),
('00007',"Walter Melon","Amsterdam"),
('00008',"Shonda Leer", "São Paulo");


INSERT INTO Invoices (invoice_number, date, VIN, customer_ID, staff_ID)
VALUES ('852399038', '2018-08-22','ZM8G7BEUQZ97IH46V','10001', '00001'),
('731166526','2018-12-31','HKNDGS7CU31E9Z7JW','20001','00002'),
('271135104', '2019-01-22','DAM41UDN3CHU2WVF6','30001','00003');

SELECT * FROM Cars;
SELECT * FROM customers;
SELECT * FROM salesperson;
SELECT * FROM invoices;