Skip to content

Solved lab #353

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
34 changes: 34 additions & 0 deletions lab_mysql_seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
USE lab_mysql;

-- Insertar datos en cars
INSERT INTO cars (vin) VALUES
('3K096I98581DH5NUP'),
('ZMG87BEUIO297IH46V'),
('RKKV0NH1HLVZU0BAM'),
('HKNDGS7CU31E9ZTJW'),
('DAM41UDN3CHU2WWF6');

-- Insertar datos en customers
INSERT INTO customers (customer_id) VALUES
(10001),
(20001),
(30001);

-- Insertar datos en salespersons
INSERT INTO salespersons (staff_id) VALUES
(00001),
(00002),
(00003),
(00004),
(00005),
(00006),
(00007),
(00008);

-- Insertar datos en invoices
INSERT INTO invoices (invoice_number, customer_id, car_id, salesperson_id) VALUES
(852399038, 1, '3K096I98581DH5NUP', 3),
(731166526, 3, 'DAM41UDN3CHU2WWF6', 5),
(271135104, 2, 'ZMG87BEUIO297IH46V', 7);

SELECT * FROM cars;
36 changes: 36 additions & 0 deletions lab_mysql_structure.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP DATABASE IF EXISTS lab_mysql;
CREATE DATABASE lab_mysql;
USE lab_mysql;
USE lab_mysql;

-- Primero eliminamos las tablas si existen (en orden correcto para evitar conflictos de claves foráneas)
DROP TABLE IF EXISTS invoices;
DROP TABLE IF EXISTS customers;
DROP TABLE IF EXISTS cars;
DROP TABLE IF EXISTS salespersons;

-- Creamos la tabla customers
CREATE TABLE customers (
customer_id INT PRIMARY KEY
);

-- Creamos la tabla cars (con vin más largo para evitar errores)
CREATE TABLE cars (
vin VARCHAR(25) PRIMARY KEY
);

-- Creamos la tabla salespersons
CREATE TABLE salespersons (
staff_id INT PRIMARY KEY
);

-- Creamos la tabla invoices con claves foráneas
CREATE TABLE invoices (
invoice_number INT AUTO_INCREMENT PRIMARY KEY,
customer_id INT,
car_id VARCHAR(25),
salesperson_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
FOREIGN KEY (car_id) REFERENCES cars(vin),
FOREIGN KEY (salesperson_id) REFERENCES salespersons(staff_id)
);