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
52 changes: 52 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CREATE DATABASE IF NOT EXISTS lab_mysql;

USE lab_mysql;

DROP TABLE IF EXISTS cars;

CREATE TABLE cars (
id INT PRIMARY KEY AUTO_INCREMENT,
VIN VARCHAR(30) UNIQUE NOT NULL,
manufacturer VARCHAR(30) NOT NULL,
model VARCHAR(30) NOT NULL,
year BIGINT,
color VARCHAR(30)
);

DROP TABLE IF EXISTS customers;

CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
cust_id BIGINT UNIQUE NOT NULL,
cust_name VARCHAR(100) NOT NULL,
cust_phone VARCHAR(30),
cust_email VARCHAR(50) NOT NULL,
cust_address VARCHAR(100),
cust_city VARCHAR(30),
cust_state VARCHAR(30),
cust_country VARCHAR(30),
cust_zipcode VARCHAR(30)
);

DROP TABLE IF EXISTS salespersons;

CREATE TABLE salespersons (
id INT PRIMARY KEY AUTO_INCREMENT,
staff_id BIGINT UNIQUE NOT NULL,
name VARCHAR(100) NOT NULL,
store VARCHAR(30)
);

DROP TABLE IF EXISTS invoices;

CREATE TABLE invoices (
id INT PRIMARY KEY AUTO_INCREMENT,
invoice_number BIGINT UNIQUE NOT NULL,
date DATETIME NOT NULL,
car INT NOT NULL,
customer INT NOT NULL,
salesperson INT NOT NULL,
CONSTRAINT fk_car FOREIGN KEY (car) REFERENCES cars(id),
CONSTRAINT fk_customer FOREIGN KEY (customer) REFERENCES customers(id),
CONSTRAINT fk_salesperson FOREIGN KEY (salesperson) REFERENCES salespersons(id)
);
36 changes: 36 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
INSERT INTO lab_mysql.cars (id, vin, manufacturer, model, year, color)
VALUES (1, '3K096I98581DHSNUP', 'Volkswagen', 'Tiguan', '2019', 'Blue'),
(2, 'M8G7BEUQZ97IH46V', 'Peugeot', 'Rifter', '2019', 'Red'),
(3, 'RKXVNNIHLVVZOUB4M', 'Ford', 'Fusion', '2018', 'White'),
(4, 'HKNDGS7CU31E9Z7JW', 'Toyota', 'RAV4', '2018', 'Silver'),
(5, 'DAM41UDN3CHU2WVF6', 'Volvo', 'V60 Cross Country', '2019', 'Gray');


INSERT INTO lab_mysql.customers (id, cust_id, cust_name, cust_phone, cust_email, cust_address, cust_city, cust_state, cust_country, cust_zipcode)
VALUES (0, '10001', 'Pablo Picasso', '+34 636 17 63 82', '-', 'Paseo de la Chopera, 14', 'Madrid', 'Madrid', 'Spain', '28045'),
(1, '20001', 'Abraham Lincoln', '+1 305 907 7086', '-', '120 SW 8th St | Miami', 'Florida', 'United States', '33130'),
(2, '30001', 'Napoléon Bonaparte', '+33 1 79 75 40 00', '-', '40 Rue du Colisée', 'Paris', 'le-de-France', 'France', '75008');


INSERT INTO lab_mysql.salespersons (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', 'Mimia'),
(6, '00006', 'Bob Frapples', 'Mexico City'),
(7, '00007', 'Walter Melon', 'Amsterdam'),
(8, '00008', 'Shonda Leer', 'São Paulo');


INSERT INTO lab_mysql.invoices (id, invoice_number, date, car, customer, salesperson)
VALUES (1, '852399038', '22-08-2018', '1', '1', '3'),
(2, '731166526', '31-12-2018', '3', '3', '5'),
(3, '271135104', '22-01-2019', '2', '2', '7');