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
Binary file added your-code/ERD.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added your-code/ERD.pptx
Binary file not shown.
60 changes: 60 additions & 0 deletions your-code/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*Create the (empty) mySQL database*/
SELECT CURRENT_USER();

CREATE DATABASE IF NOT EXISTS lab_mysql;

/*Define the database that will be used in the queries*/
USE lab_mysql;

/*Populate the database with tables*/
CREATE TABLE IF NOT EXISTS Cars(
ID INT PRIMARY KEY AUTO_INCREMENT,
VIN VARCHAR(17) NOT NULL,
Manufacturer VARCHAR(40) NOT NULL,
Model VARCHAR(40),
`Year` YEAR,
Color VARCHAR(30)
);

SELECT * FROM Cars;


CREATE TABLE IF NOT EXISTS Customers(
ID INT PRIMARY KEY AUTO_INCREMENT,
`Customer ID` INT NOT NULL,
`Name` VARCHAR(100) NOT NULL,
Phone VARCHAR(20),
Email VARCHAR(50),
Address VARCHAR(100) NOT NULL,
City VARCHAR(50) NOT NULL,
`State/Province` VARCHAR(50),
Country VARCHAR(50) NOT NULL,
Postal VARCHAR(10)
);

SELECT * FROM Customers;


CREATE TABLE IF NOT EXISTS Salespersons(
ID INT PRIMARY KEY AUTO_INCREMENT,
`Staff ID` VARCHAR(5) NOT NULL,
`Name` VARCHAR(100),
Store VARCHAR(50)
);

SELECT * FROM Salespersons;


CREATE TABLE IF NOT EXISTS Invoices(
ID INT PRIMARY KEY AUTO_INCREMENT,
`Invoice Number` INT NOT NULL,
`Date` DATE NOT NULL,
Car INT,
Customer INT,
`Sales Person` INT,
FOREIGN KEY (Car) REFERENCES Cars(ID),
FOREIGN KEY (Customer) REFERENCES Customers(ID),
FOREIGN KEY (`Sales Person`) REFERENCES Salespersons(ID)
);

SELECT * FROM Invoices;
19 changes: 19 additions & 0 deletions your-code/delete.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
USE lab_mysql;

/*To find duplicate entries*/

SELECT VIN, COUNT(*) as count
FROM Cars
GROUP BY VIN
HAVING count > 1;


/*Delete*/
SET SQL_SAFE_UPDATES = 0;

SELECT * FROM Cars;

DELETE FROM Cars
WHERE (ID = 4);

SET SQL_SAFE_UPDATES = 1;
47 changes: 47 additions & 0 deletions your-code/seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*In order to start the auto-increment attribute in mySQL starting from 0 instead of (default) 1*/
SET sql_mode = "NO_AUTO_VALUE_ON_ZERO";

USE lab_mysql;

INSERT INTO Cars
VALUES
(0, '3K096I98581DHSNUP', 'Volkswagen', 'Tiguan', 2019, 'Blue'),
(1, 'ZM8G7BEUQZ97IH46V', 'Peugeot', 'Rifter', 2019, 'Red'),
(2, 'RKXVNNIHLVVZOUB4M', 'Ford', 'Fusion', 2018, 'White'),
(3, 'HKNDGS7CU31E9Z7JW', 'Toyota', 'RAV4', 2018, 'Silver'),
(4, 'DAM41UDN3CHU2WVF6', 'Volvo', 'V60', 2019, 'Gray'),
(5, 'DAM41UDN3CHU2WVF6', 'Volvo', 'V60 Cross Country', 2019, 'Gray');

SELECT * FROM Cars;


INSERT INTO Customers
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');

SELECT * FROM Customers;


INSERT INTO Salespersons
VALUES
(0, '00001', 'Petey Cruiser', 'Madrid'),
(1, '00002', 'Anna Sthesia', 'Barcelona'),
(2, '00003', 'Paul Molive', 'Berlin'),
(3, '00004', 'Gail Forcewind', 'Paris'),
(4, '00005', 'Paige Turner', 'Mimia'),
(5, '00006', 'Bob Frapples', 'Mexico City'),
(6, '00007', 'Walter Melon', 'Amsterdam'),
(7, '00008', 'Shonda Leer', 'São Paulo');

SELECT * FROM Salespersons;


INSERT INTO Invoices
VALUES
(0, '852399038', STR_TO_DATE('22-08-2018', '%d-%m-%Y'), 0, 1, 3),
(1, '731166526', STR_TO_DATE('31-12-2018', '%d-%m-%Y'), 3, 0, 5),
(2, '271135104', STR_TO_DATE('22-01-2019', '%d-%m-%Y'), 2, 2, 7);

SELECT * FROM Invoices;
29 changes: 29 additions & 0 deletions your-code/update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
USE lab_mysql;

/*Deactivate safe updates on mySQL*/
SET SQL_SAFE_UPDATES = 0;

/*Update*/
SELECT * FROM Salespersons;

UPDATE Salespersons
SET store = 'Miami'
WHERE (ID = 4);

SELECT * FROM Customers;

UPDATE Customers
SET Email = 'ppicasso@gmail.com'
WHERE (ID = 0);

UPDATE Customers
SET Email = 'lincoln@us.gov'
WHERE (ID = 1);

UPDATE Customers
SET Email = 'hello@napoleon.me'
WHERE (ID = 2);


/*Activate safe updates on mySQL*/
SET SQL_SAFE_UPDATES = 1;