diff --git a/Challenge_1.png b/Challenge_1.png new file mode 100644 index 0000000..e0709c6 Binary files /dev/null and b/Challenge_1.png differ diff --git a/create.sql b/create.sql new file mode 100644 index 0000000..99e4233 --- /dev/null +++ b/create.sql @@ -0,0 +1,50 @@ +-- Create the database +CREATE DATABASE IF NOT EXISTS lab_mysql; +USE lab_mysql; + +-- Drop and create the cars table +DROP TABLE IF EXISTS cars; +CREATE TABLE cars ( + id INT AUTO_INCREMENT PRIMARY KEY, + vin VARCHAR(50), + manufacturer VARCHAR(50), + model VARCHAR(50), + year INT, + color VARCHAR(30) +); + +-- Drop and create the customers table +DROP TABLE IF EXISTS customers; +CREATE TABLE customers ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100), + phone VARCHAR(30), + email VARCHAR(100), + address VARCHAR(100), + city VARCHAR(50), + state VARCHAR(50), + country VARCHAR(50), + zipcode VARCHAR(20) +); + +-- Drop and create the salespersons table +DROP TABLE IF EXISTS salespersons; +CREATE TABLE salespersons ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100), + store VARCHAR(50) +); + +-- Drop and create the invoices table with relationships +DROP TABLE IF EXISTS invoices; +CREATE TABLE invoices ( + id INT AUTO_INCREMENT PRIMARY KEY, + invoice_number VARCHAR(20), + invoice_date DATE, + car_id INT, + customer_id INT, + staff_id INT, + FOREIGN KEY (car_id) REFERENCES cars(id), + FOREIGN KEY (customer_id) REFERENCES customers(id), + FOREIGN KEY (staff_id) REFERENCES salespersons(id) +); diff --git a/seeding.sql b/seeding.sql new file mode 100644 index 0000000..3102872 --- /dev/null +++ b/seeding.sql @@ -0,0 +1,25 @@ +USE lab_mysql; + +-- Insert sample data into cars +INSERT INTO cars (vin, manufacturer, model, year, color) VALUES +('1HGCM82633A004352', 'Honda', 'Accord', 2020, 'Black'), +('2T1BURHE5JC123456', 'Toyota', 'Corolla', 2019, 'White'), +('3FA6P0H73HR123789', 'Ford', 'Fusion', 2021, 'Blue'); + +-- Insert sample data into customers +INSERT INTO customers (name, phone, email, address, city, state, country, zipcode) VALUES +('Alice Johnson', '555-1234', 'alice@example.com', '123 Maple St', 'Springfield', 'IL', 'USA', '62704'), +('Bob Smith', '555-5678', 'bob@example.com', '456 Oak Ave', 'Chicago', 'IL', 'USA', '60616'), +('Charlie Brown', '555-9012', 'charlie@example.com', '789 Pine Rd', 'Naperville', 'IL', 'USA', '60540'); + +-- Insert sample data into salespersons +INSERT INTO salespersons (name, store) VALUES +('Diana Prince', 'Downtown'), +('Clark Kent', 'Uptown'), +('Bruce Wayne', 'Suburban'); + +-- Insert sample data into invoices +INSERT INTO invoices (invoice_number, invoice_date, car_id, customer_id, staff_id) VALUES +('INV001', '2023-01-15', 1, 1, 1), +('INV002', '2023-02-20', 2, 2, 2), +('INV003', '2023-03-10', 3, 3, 3);