-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_TallerMysql.sql
37 lines (22 loc) · 1.46 KB
/
1_TallerMysql.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
CREATE DATABASE concesionario CHARACTER SET utf8 COLLATE utf8_unicode_ci;
USE concesionario;
CREATE TABLE marcas(idMarca INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
nombreMarca VARCHAR(255)
);
CREATE TABLE autos( idAuto INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
nombreAuto VARCHAR(255),
precio INT,
idMarca INT NOT NULL
);
INSERT INTO marcas (nombreMarca) VALUES ('Lamborghini'), ('Audi'), ('Chevrolet'), ('Ford'), ('Renault'), ('Volkswagen');
INSERT INTO autos (nombreAuto, precio, idMarca) VALUES ("RS6", 100, 2), ("Sport Clio R.S. '11", 80, 5),
("Corvette Stingray L46 350", 500, 3), ("Mustang GT", 290, 4), ("Scirocco GT24", 140, 6), ("RS200", 640, 4),
("TT ABT Touring Car", 279, 2), ("Diablo GT '00", 1000, 1), ("Camaro Z28 Coupe", 550, 3), ("Reventon '08", 800, 1);
ALTER TABLE autos ADD CONSTRAINT fk_marca FOREIGN KEY (idMarca) REFERENCES marcas (idMarca) ON DELETE CASCADE ON UPDATE CASCADE;
/* consultas
SELECT * FROM autos WHERE nombreAuto LIKE '%GT%'
SELECT * FROM autos WHERE nombreAuto LIKE '%t'
SELECT a.nombreAuto, a.precio, m.nombreMarca FROM autos AS a INNER JOIN marcas AS m ON a.idMarca=m.idMarca WHERE precio BETWEEN 100 AND 550
ORDER BY nombreMarca ASC
SELECT a.nombreAuto, a.precio, m.nombreMarca, m.idMarca FROM autos AS a INNER JOIN marcas AS m ON a.idMarca=m.idMarca WHERE m.nombreMarca='Chevrolet' OR m.nombreMarca='Ford'
*/