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 Challenge_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -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)
);
25 changes: 25 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -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', '[email protected]', '123 Maple St', 'Springfield', 'IL', 'USA', '62704'),
('Bob Smith', '555-5678', '[email protected]', '456 Oak Ave', 'Chicago', 'IL', 'USA', '60616'),
('Charlie Brown', '555-9012', '[email protected]', '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);