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
49 changes: 49 additions & 0 deletions create.sql.sql
Original file line number Diff line number Diff line change
@@ -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`);
*/
7 changes: 7 additions & 0 deletions delete.sql
Original file line number Diff line number Diff line change
@@ -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;
Binary file added drawSQL-image-export-2025-09-16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 9 additions & 0 deletions update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Setting the working database
USE lab_mysql;
SET SQL_SAFE_UPDATES = 0;

UPDATE customers SET cust_email = '[email protected]' WHERE cust_name = 'Pablo Picasso';
UPDATE customers SET cust_email = '[email protected]' WHERE cust_name = 'Abraham Lincoln';
UPDATE customers SET cust_email = '[email protected]' WHERE cust_name = 'Napoléon Bonaparte';

select * from lab_mysql.customers;