diff --git a/E_Rcars.drawio.pdf b/E_Rcars.drawio.pdf new file mode 100644 index 0000000..bfc1fd0 Binary files /dev/null and b/E_Rcars.drawio.pdf differ diff --git a/create.sql b/create.sql new file mode 100644 index 0000000..a892ed1 --- /dev/null +++ b/create.sql @@ -0,0 +1,49 @@ +CREATE DATABASE IF NOT EXISTS lab_mysql; + +USE lab_mysql; + +DROP TABLE IF EXISTS car; +CREATE TABLE car ( +car_id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, +vin VARCHAR(30) UNIQUE NOT NULL, +manufacture VARCHAR(30) NOT NULL, +model VARCHAR(20) NOT NULL, +color VARCHAR(20) NOT NULL, +year YEAR NOT NULL); + +DROP TABLES IF EXISTS customer; +CREATE TABLE customer ( +customer_id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, +name VARCHAR (30) NOT NULL, +email VARCHAR(30) NOT NULL, +phone VARCHAR(20)NOT NULL, +address VARCHAR(20) NOT NULL, +city VARCHAR(20) NOT NULL, +state VARCHAR(20) NOT NULL, +country VARCHAR(10)NOT NULL, +zip_code VARCHAR(20)NOT NULL); + +DROP TABLES IF EXISTS salesperson; +CREATE TABLE salesperson ( +salesperson_id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, +name VARCHAR(20) NOT NULL, +email VARCHAR(30)NOT NULL, +store VARCHAR(30) NOT NULL); + +DROP TABLES IF EXISTS invoice; +CREATE TABLE invoice ( +invoice_id INT AUTO_INCREMENT PRIMARY KEY, +car_id INT NOT NULL, +customer_id INT NOT NULL, +salesperson_id INT NOT NULL, +date_of_invoice DATE NOT NULL, + +FOREIGN KEY (car_id) REFERENCES car(id), +FOREIGN KEY (customer_id) REFERENCES customer(id), +FOREIGN KEY (salesperson_id) REFERENCES salesperson(id) +); + +DESCRIBE customer + + + diff --git a/delete.sql b/delete.sql new file mode 100644 index 0000000..63fc65d --- /dev/null +++ b/delete.sql @@ -0,0 +1,4 @@ +SET SQL_SAFE_UPDATES = 0; +DELETE FROM car +WHERE car_id = 4; +SET SQL_SAFE_UPDATES = 1; \ No newline at end of file diff --git a/seeding.sql b/seeding.sql new file mode 100644 index 0000000..694672c --- /dev/null +++ b/seeding.sql @@ -0,0 +1,32 @@ +INSERT INTO car (car_id, vin, manufacture, model, year, color) +VALUES +(1, '3K096I98581DHSNUP','Volkswagen', 'Tiguan', 2019, 'Blue'), +(2, 'ZM8G7BEUQZ97IH46V', 'Peugeot', 'Rifter', 2019, 'Red'), +(3, 'RKXVNNIHLVVZOUB4M', 'Ford', 'Fusion', 2018, 'White'), +(4, 'HKNDGS7CU31E9Z7JW', 'Toyota', 'RAV4', 2018, 'Silver'), +(5, 'DAM41UDN3CHU2WVF6', 'Volvo', 'V60', 2019, 'Gray'), +(6, 'DAM41UDN3CHU2WVF8', 'Volvo', 'V60 Cross Country', 2019, 'Gray'); + +INSERT INTO customer (customer_id, name, phone, email, address, city, state, country, zip_code) +VALUES +(10001, 'Kurt Cobain', '+41 543 789 7865', '-', 'Paseo de la Chopera, 14', 'Madrid', 'Madrid', 'Spain', '28045'), +(10002, 'Abraham Lincoln', '+1 305 907 7086', '-', '120 SW 8th St', 'Miami', 'Florida', 'United States', '33130'), +(10003, 'Napoléon Bonaparte', '+33 1 79 75 40 00', '-', '40 Rue du Colisée', 'Paris', 'Île-de-France', 'France', '75008'); +(10004 +INSERT INTO salesperson (salesperson_id, name, email, store) +VALUES +('1', 'Petey Cruiser', '-', 'Madrid'), +('2', 'Anna Sthesia', '-', 'Barcelona'), +('3', 'Paul Molive', '-', 'Berlin'), +('4', 'Gail Forcewind', '-', 'Paris'), +('5', 'Paige Turner', '-', 'Mimia'), +('6', 'Bob Frapples', '-', 'Mexico City'), +('7', 'Walter Melon', '-', 'Amsterdam'), +('8', 'Shonda Leer', '-', 'São Paulo'); + +INSERT INTO invoice (invoice_number,car_id,customer_id,salesperson_id,date_of_invoice) +VALUES +(1, 1, 10001, '1', '2018-08-22'), +(3, 2, 10002, '2', '2018-12-31'), +(2, 3, 10003, '3', '2019-01-22'); + diff --git a/updates.sql b/updates.sql new file mode 100644 index 0000000..e4db767 --- /dev/null +++ b/updates.sql @@ -0,0 +1,15 @@ +SET SQL_SAFE_UPDATES = 0; +UPDATE customer +SET email = 'ppicasso@gmail.com' +WHERE name = 'Pablo Picasso'; + +UPDATE customer +SET email = 'lincoln@us.gov' +WHERE name = 'Abraham Lincoln'; + +UPDATE customer +SET email = 'hello@napoleon.me' +WHERE name = 'Napoléon Bonaparte'; + +SET SQL_SAFE_UPDATES = 1; +