diff --git a/create.sql.sql b/create.sql.sql new file mode 100644 index 0000000..3a26a98 --- /dev/null +++ b/create.sql.sql @@ -0,0 +1,49 @@ +CREATE DATABASE IF NOT EXISTS lab_mysql; +USE lab_mysql; + +-- DROP TABLE IF EXISTS cars; +CREATE TABLE `cars`( + `id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `vin` VARCHAR(255) NOT NULL, + `manufacturer` CHAR(255) NOT NULL, + `model` VARCHAR(255) NOT NULL, + `year` INT NOT NULL, + `color` CHAR(255) NOT NULL +); +-- DROP TABLE IF EXISTS customers; +CREATE TABLE `customers`( + `cust_id` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `cust_name` CHAR(255) NOT NULL, + `cust_phone` VARCHAR(255) NOT NULL, + `cust_email` CHAR(255) NULL, + `cust_address` VARCHAR(255) NOT NULL, + `cust_city` CHAR(255) NOT NULL, + `cust_state` CHAR(255) NOT NULL, + `cust_country` CHAR(255) NOT NULL, + `cust_zipcode` INT NOT NULL +); +-- DROP TABLE IF EXISTS salespersons; +CREATE TABLE `salespersons`( + `staff_ID` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `name` CHAR(255) NOT NULL, + `store` CHAR(255) NOT NULL +); +-- DROP TABLE IF EXISTS invoices; +CREATE TABLE `invoices`( + `invoice_number` int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `date` date NOT NULL, + `car` int UNSIGNED NOT NULL, + `customer` int UNSIGNED NOT NULL, + `salesperson` int UNSIGNED NOT NULL, + FOREIGN KEY(`car`) REFERENCES `cars`(`id`), + FOREIGN KEY(`customer`) REFERENCES `customers`(`cust_id`), + FOREIGN KEY(`salesperson`) REFERENCES `salespersons`(`staff_ID`) +); +/* +ALTER TABLE + `invoices` ADD CONSTRAINT `invoices_car_foreign` FOREIGN KEY(`car`) REFERENCES `cars`(`id`); +ALTER TABLE + `invoices` ADD CONSTRAINT `invoices_customerint_foreign` FOREIGN KEY(`customerint`) REFERENCES `customers`(`cust_id`); +ALTER TABLE + `invoices` ADD CONSTRAINT `invoices_salespersonint_foreign` FOREIGN KEY(`salespersonint`) REFERENCES `salespersons`(`staff_ID`); +*/ \ No newline at end of file diff --git a/delete.sql b/delete.sql new file mode 100644 index 0000000..3a65794 --- /dev/null +++ b/delete.sql @@ -0,0 +1,7 @@ +-- Setting the working database +USE lab_mysql; +SET SQL_SAFE_UPDATES = 0; + +DELETE FROM cars WHERE id = 4 AND vin = 'DAM41UDN3CHU2WVF6'; + +select * from lab_mysql.cars; \ No newline at end of file diff --git a/drawSQL-image-export-2025-09-16.png b/drawSQL-image-export-2025-09-16.png new file mode 100644 index 0000000..39a8eec Binary files /dev/null and b/drawSQL-image-export-2025-09-16.png differ diff --git a/seeding.sql b/seeding.sql new file mode 100644 index 0000000..4a55417 --- /dev/null +++ b/seeding.sql @@ -0,0 +1,35 @@ +-- Setting the working database +USE lab_mysql; + +INSERT INTO cars (vin, manufacturer, model, year, color) +VALUES ('K096I98581DHSNUP','Volkswagen','Tiguan','2019','Blue'), +('M8G7BEUQZ97IH46V','Peugeot','Rifter','2019','Red'), +('RKXVNNIHLVVZOUB4M','Ford','Fusion','2018','White'), +('KNDGS7CU31E9Z7JW','Toyota','RAV4','2018','Silver'), +('DAM41UDN3CHU2WVF6','Volvo','V60','2019','Gray'), +('AM41UDN3CHU2WVF6','Volvo','V60 Cross Country','2019','Gray'); + +INSERT INTO customers (cust_name, cust_phone, cust_email, cust_address, cust_city, cust_state, cust_country, cust_zipcode) +VALUE ('Pablo Picasso','+34 636 17 63 82','-','Paseo de la Chopera, 14','Madrid','Madrid','Spain','28045'), +('Abraham Lincoln','+1 305 907 7086','-','120 SW 8th St', 'Miami','Florida','United States','33130'), +('Napoléon Bonaparte','+33 1 79 75 40 00','-','40 Rue du Colisée','Paris','Île-de-France','France','75008'); + +INSERT INTO salespersons (name, store) +VALUE ('Petey Cruiser','Madrid'), +('Anna Sthesia','Barcelona'), +('Paul Molive','Berlin'), +('Gail Forcewind','Paris'), +('Paige Turner','Mimia'), +('Bob Frapples','Mexico City'), +('Walter Melon','Amsterdam'), +('Shonda Leer','São Paulo'); + +INSERT INTO lab_mysql.invoices (date, car, customer, salesperson) +VALUE ('2018-08-22', '1', '1', '3'), + ('2018-12-31', '3', '3', '5'), + ('2019-01-22', '2', '2', '7'); + +select * from lab_mysql.cars; +select * from lab_mysql.customers; +select * from lab_mysql.salespersons; +select * from lab_mysql.invoices; diff --git a/update.sql b/update.sql new file mode 100644 index 0000000..eadc6a9 --- /dev/null +++ b/update.sql @@ -0,0 +1,9 @@ +-- Setting the working database +USE lab_mysql; +SET SQL_SAFE_UPDATES = 0; + +UPDATE customers SET cust_email = 'ppicasso@gmail.com' WHERE cust_name = 'Pablo Picasso'; +UPDATE customers SET cust_email = 'lincoln@us.gov' WHERE cust_name = 'Abraham Lincoln'; +UPDATE customers SET cust_email = 'hello@napoleon.me' WHERE cust_name = 'Napoléon Bonaparte'; + +select * from lab_mysql.customers; \ No newline at end of file