Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lab-mysql] Bruno Santos #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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.
51 changes: 51 additions & 0 deletions your-code/create.sql
Original file line number Diff line number Diff line change
@@ -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;

1 change: 1 addition & 0 deletions your-code/delete.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM lab_mysql.car WHERE (`ID` = '6');
31 changes: 31 additions & 0 deletions your-code/seeding.sql
Original file line number Diff line number Diff line change
@@ -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' );


6 changes: 6 additions & 0 deletions your-code/update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UPDATE lab_mysql.salesperson SET store = 'Miami' WHERE (staff_number = 5);

UPDATE lab_mysql.costumer SET `email` = '[email protected]' WHERE (`costumer_number` = '1');
UPDATE lab_mysql.costumer SET `email` = '[email protected]' WHERE (`costumer_number` = '2');
UPDATE lab_mysql.costumer SET `email` = '[email protected]' WHERE (`costumer_number` = '3');