From b99ff3e4197d5e4d8a577f47cd3ce2e738287ab8 Mon Sep 17 00:00:00 2001 From: NodrrS Date: Tue, 12 Aug 2025 15:33:09 +0200 Subject: [PATCH] Solved lab --- create.sql | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ seeding.sql | 27 +++++++++++++++++++++++++++ testing.sql | 1 + 3 files changed, 78 insertions(+) create mode 100644 create.sql create mode 100644 seeding.sql create mode 100644 testing.sql diff --git a/create.sql b/create.sql new file mode 100644 index 0000000..67f3d37 --- /dev/null +++ b/create.sql @@ -0,0 +1,50 @@ +CREATE DATABASE IF NOT EXISTS lab_mysql; +USE lab_mysql; + +DROP TABLE IF EXISTS Invoices; + +DROP TABLE IF EXISTS Cars; +DROP TABLE IF EXISTS Customers; +DROP TABLE IF EXISTS Salesperson; + +CREATE TABLE Cars ( + car_id INT PRIMARY KEY, + VIN VARCHAR(17) UNIQUE NOT NULL, + manufacturer VARCHAR(50) NOT NULL, + model VARCHAR(50) NOT NULL, + year YEAR NOT NULL, + colour VARCHAR(30) +); + +CREATE TABLE Customers ( + customer_id INT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + phone_number VARCHAR(20), + email VARCHAR(100), + address VARCHAR(255), + city VARCHAR(50), + state VARCHAR(50), + country VARCHAR(50), + post_code VARCHAR(20) +); + +CREATE TABLE Salesperson ( + staff_id INT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + store VARCHAR(100) +); + +CREATE TABLE Invoices ( + invoice_id INT PRIMARY KEY, + invoice_number VARCHAR(50) UNIQUE NOT NULL, + date DATE NOT NULL, + car_id INT NOT NULL, + customer_id INT NOT NULL, + staff_id INT NOT NULL, + FOREIGN KEY (car_id) REFERENCES Cars(car_id), + FOREIGN KEY (customer_id) REFERENCES Customers(customer_id), + FOREIGN KEY (staff_id) REFERENCES Salesperson(staff_id) +); + + +show tables \ No newline at end of file diff --git a/seeding.sql b/seeding.sql new file mode 100644 index 0000000..3412a9e --- /dev/null +++ b/seeding.sql @@ -0,0 +1,27 @@ +INSERT INTO Cars (car_id, VIN, manufacturer, model, year, colour) VALUES +(1, '3K096I98581DHSNUP', 'Volkswagen', 'Tiguan', 2019, 'Blue'), +(2, 'ZM8G7BEUQZ97IH46V', 'Peugeot', 'Rifter', 2019, 'Red'), +(3, 'RKXVNNIHLVVZOUB4M', 'Ford', 'Fusion', 2018, 'White'), +(4, 'HKNDGS7CU31E9Z7JW', 'Toyota', 'RAV4', 2018, 'Silver'), +(5, 'DAM41UDN3CHU2WVF6', 'Volvo', 'V60', 2019, 'Gray'), +(6, 'DAM41UDN3CHU2WVJ7', 'Volvo', 'V60 Cross Country', 2019, 'Gray'); + +INSERT INTO Customers (customer_id, name, phone_number, email, address, city, state, country, post_code) VALUES +(10001, 'Pablo Picasso', '+34 636 17 63 82', NULL, 'Paseo de la Chopera, 14', 'Madrid', 'Madrid', 'Spain', '28045'), +(20001, 'Abraham Lincoln', '+1 305 907 7086', NULL, '120 SW 8th St', 'Miami', 'Florida', 'United States', '33130'), +(30001, 'Napoléon Bonaparte', '+33 1 79 75 40 00', NULL, '40 Rue du Colisée', 'Paris', 'Île-de-France', 'France', '75008'); + +INSERT INTO Salesperson (staff_id, name, store) VALUES +(1, 'Petey Cruiser', 'Madrid'), +(2, 'Anna Sthesia', 'Barcelona'), +(3, 'Paul Molive', 'Berlin'), +(4, 'Gail Forcewind', 'Paris'), +(5, 'Paige Turner', 'Miami'), +(6, 'Bob Frapples', 'Mexico City'), +(7, 'Walter Melon', 'Amsterdam'), +(8, 'Shonda Leer', 'São Paulo'); + +INSERT INTO Invoices (invoice_id, invoice_number, date, car_id, customer_id, staff_id) VALUES +(1, '852399038', '2018-08-22', 1, 10001, 3), +(2, '731166526', '2018-12-31', 3, 30001, 5), +(3, '271135104', '2019-01-22', 2, 20001, 7); \ No newline at end of file diff --git a/testing.sql b/testing.sql new file mode 100644 index 0000000..896d2bd --- /dev/null +++ b/testing.sql @@ -0,0 +1 @@ +SELECT * FROM Salesperson LIMIT 10; \ No newline at end of file