diff --git a/your-code/ERD.JPG b/your-code/ERD.JPG new file mode 100644 index 0000000..61421c0 Binary files /dev/null and b/your-code/ERD.JPG differ diff --git a/your-code/create.sql b/your-code/create.sql index e69de29..9783fe6 100644 --- a/your-code/create.sql +++ b/your-code/create.sql @@ -0,0 +1,51 @@ +USE lab_mysql; + +CREATE TABLE car (VIN INT, manufacturer VARCHAR(20), + model VARCHAR(20), year_car timestamp, color VARCHAR(20)); + +CREATE TABLE invoices (invoice_number INT, invoice_date timestamp, + model VARCHAR(20), year_car timestamp, VIN INT, costumer_id int, staff_id INT); + +CREATE TABLE salesperson (staff_number INT AUTO_INCREMENT PRIMARY KEY, staff_id INT, + staff_name VARCHAR(20), store VARCHAR(20)); + +CREATE TABLE costumer (costumer_number INT AUTO_INCREMENT PRIMARY KEY, costumer_id INT, + name VARCHAR(20), phone_number VARCHAR(20), email VARCHAR(20) , address VARCHAR(20), city VARCHAR(20), state VARCHAR(20), country VARCHAR(20), ZIP VARCHAR(20)); + +ALTER TABLE car +ADD CONSTRAINT primary_car_key PRIMARY KEY (VIN); + + +ALTER TABLE invoices +ADD CONSTRAINT primary_invoices_key PRIMARY KEY (invoice_number); + +ALTER TABLE invoices +ADD CONSTRAINT foreign_invoices_key FOREIGN KEY (car_id) +REFERENCES car (ID); + +CREATE INDEX idx_costumer_id +ON costumer (costumer_id); + +ALTER TABLE invoices +ADD CONSTRAINT foreign_invoices_key4 FOREIGN KEY (costumer_id) +REFERENCES costumer (costumer_id); + +CREATE INDEX idx_staff_id +ON salesperson (staff_id); + +ALTER TABLE invoices +ADD CONSTRAINT foreign_invoices_key5 FOREIGN KEY (staff_id) +REFERENCES salesperson (staff_id); + +ALTER TABLE car +ADD COLUMN ID INT AUTO_INCREMENT PRIMARY KEY; + +ALTER TABLE invoices +ADD COLUMN ID INT AUTO_INCREMENT PRIMARY KEY; + +ALTER TABLE car +DROP CONSTRAINT primary_car_key ; + +ALTER TABLE car +ADD COLUMN ID INT AUTO_INCREMENT PRIMARY KEY; + diff --git a/your-code/delete.sql b/your-code/delete.sql index e69de29..56bd700 100644 --- a/your-code/delete.sql +++ b/your-code/delete.sql @@ -0,0 +1 @@ +DELETE FROM lab_mysql.car WHERE (`ID` = '6'); \ No newline at end of file diff --git a/your-code/seeding.sql b/your-code/seeding.sql index e69de29..c0d5a3b 100644 --- a/your-code/seeding.sql +++ b/your-code/seeding.sql @@ -0,0 +1,31 @@ +SET sql_mode = "NO_AUTO_VALUE_ON_ZERO"; + +INSERT INTO lab_mysql.car (VIN, manufacturer, model, year_car, 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 lab_mysql.costumer (costumer_id, name, phone_number, address, city,state,country,ZIP) +Values ( 10001 , 'Pablo Picasso', '+34 636 17 63 82', 'Paseo de la Chopera, 14', 'Madrid','Madrid','Spain', "28045" ); + +INSERT INTO lab_mysql.costumer (costumer_id, name, phone_number, address, city,state,country,ZIP) +Values ( 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 lab_mysql.invoices (invoice_number, invoice_date, car_id, costumer_id, staff_id) +Values ('852399038', 22-08-2018, 0, 1, 3 ); + +INSERT INTO lab_mysql.salesperson (staff_id, name, store) +Values ('00001', 'Petey Cruiser', 'Madrid'), + ('00002', ' Sthesia', 'Barcelona'), + ('00003', 'Paul Molive','Berlin' ), + ('00004', 'Gail Forcewind','Paris' ), + ('00005', 'Paige Turner','Mimia' ), + ('00006', 'Bob Frapples','Mexico City' ), + ('00007', 'Walter Melon','Amsterdam' ), + ('00008','Shonda Leer','São Paulo' ); + + diff --git a/your-code/update.sql b/your-code/update.sql index e69de29..361dfc9 100644 --- a/your-code/update.sql +++ b/your-code/update.sql @@ -0,0 +1,6 @@ +UPDATE lab_mysql.salesperson SET store = 'Miami' WHERE (staff_number = 5); + +UPDATE lab_mysql.costumer SET `email` = 'ppicasso@gmail.com' WHERE (`costumer_number` = '1'); +UPDATE lab_mysql.costumer SET `email` = 'lincoln@us.gov' WHERE (`costumer_number` = '2'); +UPDATE lab_mysql.costumer SET `email` = 'hello@napoleon.me' WHERE (`costumer_number` = '3'); +