Skip to content
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
50 changes: 50 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CREATE DATABASE IF NOT EXISTS lab_mysql;
USE lab_mysql;
DROP TABLE IF EXISTS Invoice;
DROP TABLE IF EXISTS Cars;
DROP TABLE IF EXISTS Salespersons;
DROP TABLE IF EXISTS customer;

CREATE TABLE `customer` (
`customer_ID` INT NOT NULL,
`customer_auto_id` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`phone` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL,
`address` VARCHAR(255) NOT NULL,
`city` VARCHAR(255) NOT NULL,
`state` VARCHAR(255) NOT NULL,
`country` VARCHAR(255) NOT NULL,
`zip_code` VARCHAR(255) NOT NULL,
PRIMARY KEY(`customer_auto_id`)
);

CREATE TABLE `Cars` (
`identification_number_VIN` CHAR(17) NOT NULL,
`manufacturer` VARCHAR(255) NOT NULL,
`model` VARCHAR(255) NOT NULL,
`year` YEAR NOT NULL,
`color` VARCHAR(255) NOT NULL,
PRIMARY KEY(`identification_number_VIN`)
);

CREATE TABLE `Salespersons` (
`salesperson_auto_id` INT NOT NULL,
`staff_ID` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL,
`store` VARCHAR(255) NOT NULL,
PRIMARY KEY(`salesperson_auto_id`)
);

CREATE TABLE `Invoice` (
`invoice_auto_id` INT NOT NULL,
`number` VARCHAR(255) NOT NULL,
`date` DATE NOT NULL,
`car` CHAR(17) NOT NULL,
`customer` VARCHAR(255) NOT NULL,
`salesperson` INT NOT NULL,
PRIMARY KEY(`invoice_auto_id`),
FOREIGN KEY(`customer`) REFERENCES `customer`(`customer_auto_id`),
FOREIGN KEY(`salesperson`) REFERENCES `Salespersons`(`salesperson_auto_id`),
FOREIGN KEY(`car`) REFERENCES `Cars`(`identification_number_VIN`)
);
Binary file added schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
USE lab_mysql;

INSERT INTO Cars (identification_number_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'),
('DAM41UDN3CHU2WVF7', 'Volvo', 'V60 Cross Country', 2019, 'Gray');

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

INSERT INTO Salespersons (salesperson_auto_id, staff_ID, name, store)
VALUES
(1, '00001', 'Petey Cruiser', 'Madrid'),
(2, '00002', 'Anna Sthesia', 'Barcelona'),
(3, '00003', 'Paul Molive', 'Berlin'),
(4, '00004', 'Gail Forcewind', 'Paris'),
(5, '00005', 'Paige Turner', 'Miami'),
(6, '00006', 'Bob Frapples', 'Mexico City'),
(7, '00007', 'Walter Melon', 'Amsterdam'),
(8, '00008', 'Shonda Leer', 'São Paulo');

INSERT INTO Invoice (invoice_auto_id, number, date, car, customer, salesperson)
VALUES
(1, '852399038', '2018-08-22', '3K096I98581DHSNUP', '10001', 3),
(2, '731166526', '2018-12-31', 'RKXVNNIHLVVZOUB4M', '30001', 5),
(3, '271135104', '2019-01-22', 'ZM8G7BEUQZ97IH46V', '20001', 7);