Skip to content

sql lab 1 #359

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

Open
wants to merge 1 commit into
base: main
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
41 changes: 41 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
CREATE DATABASE IF NOT EXISTS lab_mysql;

USE lab_mysql;

CREATE TABLE cars (
id INT AUTO_INCREMENT PRIMARY KEY,
car_id VARCHAR(20) UNIQUE,
make VARCHAR(50),
model VARCHAR(50),
year INT,
price decimal(10,2),
available BOOLEAN DEFAULT TRUE
);
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_id VARCHAR(20) UNIQUE,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
phone VARCHAR(20),
address TEXT
);
CREATE TABLE salespersons (
id INT AUTO_INCREMENT PRIMARY KEY,
staff_code VARCHAR(20) UNIQUE,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
phone VARCHAR(20)
);
CREATE TABLE invoices (
invoice_id INT AUTO_INCREMENT PRIMARY KEY,
car_id INT,
customer_id INT,
salesperson_id INT,
sale_date DATE,
sale_price DECIMAL(10, 2),
FOREIGN KEY (car_id) REFERENCES cars(id),
FOREIGN KEY (customer_id) REFERENCES customers(id),
FOREIGN KEY (salesperson_id) REFERENCES salespersons(id)
);
26 changes: 26 additions & 0 deletions seeding.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
USE lab_mysql;

-- Cars
INSERT INTO cars (make, model, year, price, available)
VALUES
('Toyota', 'Yaris', 2020, 24000.00, TRUE),
('Honda', 'Civic', 2021, 22000.00, TRUE),
('Ford', 'Focus', 2019, 26000.00, FALSE);

-- Customers
INSERT INTO customers (first_name, last_name, email, phone, address)
VALUES
('John', 'Smith', '[email protected]', '617788998', '1 Lakeside Road'),
('Max', 'Pisolkar', '[email protected]', '616524865', '2 Fox Lane');

-- Salespersons
INSERT INTO salespersons (first_name, last_name, email, phone)
VALUES
('Harry', 'Kane', '[email protected]', '88877555'),
('Brennan', 'Johnson', '[email protected]', '99988777');

-- Invoices
INSERT INTO invoices (car_id, customer_id, salesperson_id, sale_date, sale_price)
VALUES
(1, 1, 1, '2025-05-25', 24000.00),
(2, 2, 2, '2025-05-26', 22000.00);