Hatkat

BaseDeDatos_Libreria

Dec 26th, 2023 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 10.06 KB | None | 0 0
  1. CREATE DATABASE libreria;
  2. USE libreria;
  3.  
  4. CREATE TABLE Autor (
  5.     idAutor SMALLINT NOT NULL AUTO_INCREMENT,
  6.     nombreAutor VARCHAR(50) NOT NULL,
  7.     apellidoAutor VARCHAR(50) NOT NULL,
  8.     correoAutor VARCHAR(50),
  9.     NacimientoAutor DATE NOT NULL,
  10.     PRIMARY KEY (idAutor)
  11. );
  12. INSERT INTO Autor (idAutor, nombreAutor, apellidoAutor, correoAutor, NacimientoAutor) VALUES
  13.     (DEFAULT, 'Pablo', 'Neruda', '[email protected]', '1904-07-12'),
  14.     (DEFAULT, 'Octavio', 'Paz', NULL, '1914-03-31'),
  15.     (DEFAULT, 'Rubén', 'Darío', '[email protected]', '1867-01-18'),
  16.     (DEFAULT, 'Miguel', 'Ángel', '[email protected]', '1899-05-20'),
  17.     (DEFAULT, 'César', 'Vallejo', NULL, '1892-03-16'),
  18.     (DEFAULT, 'Gabriela', 'Mistral', '[email protected]', '1889-04-07'),
  19.     (DEFAULT, 'Claribel', 'Alegría', '[email protected]', '1924-05-12'),
  20.     (DEFAULT, 'Julio', 'Cortázar', NULL, '1914-08-26'),
  21.     (DEFAULT, 'Juan', 'Rulfo', '[email protected]', '1917-05-16'),
  22.     (DEFAULT, 'José', 'Donoso', NULL, '1924-10-05');
  23.  
  24. CREATE TABLE Editorial (
  25.     idEditorial SMALLINT NOT NULL AUTO_INCREMENT,
  26.     nombreEditorial VARCHAR(50) NOT NULL,
  27.     telefonoEditorial VARCHAR(25) NOT NULL,
  28.     correoEditorial VARCHAR(50) NOT NULL,
  29.     webEditorial VARCHAR(100) NOT NULL,
  30.     PRIMARY KEY (idEditorial)
  31. );
  32. INSERT INTO Editorial (idEditorial, nombreEditorial, telefonoEditorial, correoEditorial, webEditorial) VALUES
  33.     (DEFAULT, 'Ediciones del Sur Argentina', '+54 1112345678', '[email protected]', 'www.edicionesdelsur.com.ar'),
  34.     (DEFAULT, 'Editorial Nacional Brasileña', '+55 21987654321', '[email protected]', 'www.editorialnacional.com.br'),
  35.     (DEFAULT, 'Publicaciones Chilena S.A.', '+56 2 87654321', '[email protected]', 'www.publicacioneschilena.cl'),
  36.     (DEFAULT, 'Ediciones Centroamericana', '+502 2222-3333', '[email protected]', 'www.edicionescentroamericana.gt'),
  37.     (DEFAULT, 'Editorial Ecuatoriana Andina', '+593 2555-6666', '[email protected]', 'www.editorialecuatoriana.com.ec'),
  38.     (DEFAULT, 'Libros Caribeños Colombia', '+57 1 4445555', '[email protected]', 'www.libroscaribenos.com.co'),
  39.     (DEFAULT, 'Ediciones Caribe México', '+52 55 7777-8888', '[email protected]', 'www.edicionescaribe.mx'),
  40.     (DEFAULT, 'Editorial Sudamericana Perú', '+51 699888777', '[email protected]', 'www.editorialsudamericana.pe'),
  41.     (DEFAULT, 'Publicaciones Latinoamérica', '+598 23333-4444', '[email protected]', 'www.publicacioneslatinoamerica.com.uy'),
  42.     (DEFAULT, 'Ediciones Panamá Internacional', '+507 6666-7777', '[email protected]', 'www.edicionespanama.com.pa');
  43.  
  44. CREATE TABLE LugarImpresion (
  45.     idLugarImpresion SMALLINT NOT NULL AUTO_INCREMENT,
  46.     direccionLugar VARCHAR(100) NOT NULL,
  47.     capacidadProduccion INT,
  48.     estadoOperativo BOOLEAN,
  49.     PRIMARY KEY (idLugarImpresion)
  50. );
  51. INSERT INTO LugarImpresion (idLugarImpresion, direccionLugar, capacidadProduccion, estadoOperativo) VALUES
  52.     (DEFAULT, 'Av. Independencia 123, Buenos Aires, Argentina', 5000, TRUE),
  53.     (DEFAULT, 'Rua das Letras 456, Rio de Janeiro, Brasil', 7000, TRUE),
  54.     (DEFAULT, 'Calle de las Imprentas, Santiago, Chile', 6000, TRUE),
  55.     (DEFAULT, 'Avenida de las Ediciones, Guatemala City, Guatemala', 4500, TRUE),
  56.     (DEFAULT, 'Avenida de las Publicaciones , Quito, Ecuador', 5500, TRUE),
  57.     (DEFAULT, 'Carrera de los Libros 567, Bogotá, Colombia', 4800, TRUE),
  58.     (DEFAULT, 'Calle de los Libros 890, Ciudad de México, México', 7200, TRUE),
  59.     (DEFAULT, 'Avenida de las Editoriales, Lima, Perú', 5300, TRUE),
  60.     (DEFAULT, 'Calle de las Publicaciones ABC, Montevideo, Uruguay', 5100, TRUE),
  61.     (DEFAULT, 'Avenida de las Impresiones, Panamá City, Panamá', 4700, TRUE);
  62.  
  63. CREATE TABLE Edicion (
  64.     idEdicion SMALLINT NOT NULL AUTO_INCREMENT,
  65.     DetalleEdicion VARCHAR(50) NOT NULL,
  66.     PRIMARY KEY (idEdicion)
  67. );
  68. INSERT INTO Edicion (idEdicion, DetalleEdicion) VALUES
  69.     (DEFAULT, 'Primera Edición'),
  70.     (DEFAULT, 'Segunda Edición'),
  71.     (DEFAULT, 'Tercera Edición'),
  72.     (DEFAULT, 'Cuarta Edición'),
  73.     (DEFAULT, 'Quinta Edición'),
  74.     (DEFAULT, 'Sexta Edición'),
  75.     (DEFAULT, 'Edición Limitada'),
  76.     (DEFAULT, 'Edición Especial'),
  77.     (DEFAULT, 'Edición Comercial'),
  78.     (DEFAULT, 'Edición No Comercial');
  79.  
  80. CREATE TABLE IdiomaPais (
  81.     idIdiomaPais SMALLINT NOT NULL AUTO_INCREMENT,
  82.     nombreIdioma VARCHAR(50) NOT NULL,
  83.     PRIMARY KEY (idIdiomaPais)
  84. );
  85. INSERT INTO IdiomaPais (idIdiomaPais, nombreIdioma) VALUES
  86.     (DEFAULT, 'Español'),
  87.     (DEFAULT, 'Portugués'),
  88.     (DEFAULT, 'Inglés');
  89.  
  90. CREATE TABLE Pais (
  91.     idPais SMALLINT NOT NULL AUTO_INCREMENT,
  92.     nombrePais VARCHAR(50) NOT NULL,
  93.     capital VARCHAR(50),
  94.     idIdiomaPais SMALLINT NOT NULL,
  95.     PRIMARY KEY (idPais),
  96.     FOREIGN KEY (idIdiomaPais) REFERENCES IdiomaPais(idIdiomaPais)
  97.     ON DELETE RESTRICT ON UPDATE CASCADE
  98. );
  99. INSERT INTO Pais (idPais, nombrePais, capital, idIdiomaPais) VALUES
  100.     (DEFAULT, 'Ecuador', 'Quito', 1),
  101.     (DEFAULT, 'Brasil', 'Brasilia', 2),
  102.     (DEFAULT, 'Argentina', 'Buenos Aires', 1),
  103.     (DEFAULT, 'México', 'Ciudad de México', 1),
  104.     (DEFAULT, 'Colombia', 'Bogotá', 1),
  105.     (DEFAULT, 'Perú', 'Lima', 1),
  106.     (DEFAULT, 'Chile', 'Santiago', 1),
  107.     (DEFAULT, 'Venezuela', 'Caracas', 1),
  108.     (DEFAULT, 'Guatemala', 'Ciudad de Guatemala', 1),
  109.     (DEFAULT, 'Estados Unidos de América', 'Washington D.C.', 3);
  110.  
  111. CREATE TABLE TipoLibro (
  112.     idTipoLibro SMALLINT NOT NULL AUTO_INCREMENT,
  113.     tipoLibro VARCHAR(100) NOT NULL,
  114.     detalleTipoLibro TEXT NOT NULL,
  115.     PRIMARY KEY (idTipoLibro)
  116. );
  117. INSERT INTO TipoLibro (idTipoLibro, tipoLibro, detalleTipoLibro) VALUES
  118.     (DEFAULT, 'Poesía', 'Emociones en versos y rimas'),
  119.     (DEFAULT, 'Política', 'El juego del poder y la sociedad'),
  120.     (DEFAULT, 'Economía', 'Dinero y comportamiento financiero'),
  121.     (DEFAULT, 'Aventura', 'Emoción y riesgo en historias'),
  122.     (DEFAULT, 'Cocina', 'Recetas y secretos culinarios'),
  123.     (DEFAULT, 'Religión', 'Creencias y espiritualidad'),
  124.     (DEFAULT, 'Viajes', 'Aventuras en distintos lugares'),
  125.     (DEFAULT, 'Tecnología', 'Avances y cambio en la era digital'),
  126.     (DEFAULT, 'Psicología', 'Mente, emociones y comportamiento'),
  127.     (DEFAULT, 'Medicina', 'Salud y bienestar personal');
  128.  
  129. CREATE TABLE Libro (
  130.     idLibro SMALLINT NOT NULL AUTO_INCREMENT,
  131.     tituloLibro VARCHAR(100) NOT NULL,
  132.     isbnLibro VARCHAR(20) NOT NULL,
  133.     fechaPublicacion DATE NOT NULL,
  134.     cantidadPaginas SMALLINT NOT NULL,
  135.     precioLibro FLOAT NOT NULL,
  136.     idLugarImpresion SMALLINT NOT NULL,
  137.     FOREIGN KEY (idLugarImpresion) REFERENCES LugarImpresion(idLugarImpresion)
  138.     ON DELETE RESTRICT
  139.     ON UPDATE CASCADE,
  140.     idEditorial SMALLINT NOT NULL,
  141.     FOREIGN KEY (idEditorial) REFERENCES Editorial(idEditorial)
  142.     ON DELETE RESTRICT ON UPDATE CASCADE,
  143.     idTipoLibro SMALLINT NOT NULL,
  144.     FOREIGN KEY (idTipoLibro) REFERENCES TipoLibro(idTipoLibro)
  145.     ON DELETE RESTRICT
  146.     ON UPDATE CASCADE,
  147.     idPais SMALLINT NOT NULL,
  148.     FOREIGN KEY (idPais) REFERENCES Pais(idPais)
  149.     ON DELETE RESTRICT
  150.     ON UPDATE CASCADE,
  151.     idEdicion SMALLINT NOT NULL,
  152.     FOREIGN KEY (idEdicion) REFERENCES Edicion(idEdicion)
  153.     ON DELETE RESTRICT
  154.     ON UPDATE CASCADE,
  155.     PRIMARY KEY (idLibro),
  156.     idAutor SMALLINT NOT NULL,
  157.     FOREIGN KEY (idAutor) REFERENCES Autor(idAutor)
  158.     ON DELETE RESTRICT
  159.     ON UPDATE CASCADE
  160. );
  161. INSERT INTO Libro (idLibro, tituloLibro, isbnLibro, precioLibro, cantidadPaginas, fechaPublicacion, idLugarImpresion, idEditorial, idTipoLibro, idPais, idEdicion, idAutor) VALUES
  162.     (DEFAULT, 'El arte de la guerra', '9781973986720', 7.20, 240, '1978-01-01', 1, 4, 3, 2, 7, 5),
  163.     (DEFAULT, 'Moby Dick', '9788491052147', 6.90, 672, '1851-10-18', 3, 9, 5, 1, 3, 9),
  164.     (DEFAULT, 'El guardián entre el centeno', '9780316769488', 7.40, 234, '1951-07-16', 9, 5, 1, 4, 5, 2),
  165.     (DEFAULT, 'Las uvas de la ira', '9780142000663', 7.10, 464, '1939-04-14', 2, 6, 4, 10, 1, 8),
  166.     (DEFAULT, 'Drácula', '9788491051500', 6.85, 418, '1897-05-26', 1, 8, 6, 7, 10, 4),
  167.     (DEFAULT, 'La Odisea', '9780140268867', 7.30, 416, '1611-01-01', 5, 3, 7, 9, 6, 3),
  168.     (DEFAULT, 'El viejo y el mar', '9788491052148', 6.60, 127, '1952-09-01', 10, 7, 4, 8, 9, 6),
  169.     (DEFAULT, 'La divina comedia', '9780141197494', 7.55, 798, '1472-01-01', 8, 1, 5, 3, 8, 7),
  170.     (DEFAULT, 'La isla del tesoro', '9788426132021', 7.25, 312, '1883-01-01', 7, 2, 8, 6, 2, 10),
  171.     (DEFAULT, 'El proceso', '9788491051501', 7.10, 255, '1925-01-01', 4, 10, 3, 5, 4, 1),
  172.     (DEFAULT, 'Robinson Crusoe', '9780141199061', 6.80, 320, '1719-04-25', 1, 5, 9, 2, 3, 8),
  173.     (DEFAULT, 'Hamlet', '9780143794980', 7.60, 342, '1603-01-01', 2, 9, 6, 8, 7, 5),
  174.     (DEFAULT, 'Cien sonetos de amor', '9788426401240', 7.45, 96, '1959-01-01', 3, 6, 1, 4, 5, 9),
  175.     (DEFAULT, 'Alicia en el país de las maravillas', '9788491050062', 6.95, 272, '1865-07-04', 4, 1, 7, 6, 10, 2),
  176.     (DEFAULT, 'La guerra y la paz', '9788499890937', 7.80, 1300, '1869-01-01', 5, 1, 8, 3, 2, 7),
  177.     (DEFAULT, 'La historia interminable', '9788420432292', 7.35, 448, '1979-01-01', 6, 10, 4, 9, 1, 6),
  178.     (DEFAULT, 'La ladrona de libros', '9788499890937', 7.25, 576, '2005-01-01', 7, 3, 9, 10, 6, 5),
  179.     (DEFAULT, 'El nombre del viento', '9788401343610', 7.70, 896, '2007-03-27', 8, 5, 9, 7, 8, 4),
  180.     (DEFAULT, 'El alquimista', '9780062502186', 7.15, 197, '1988-01-01', 9, 1, 3, 1, 5, 10),
  181.     (DEFAULT, 'La casa de los espíritus', '9788408182811', 7.50, 528, '1982-01-01', 10, 5, 9, 6, 4, 3),
  182.     (DEFAULT, 'La fiesta del Chivo', '9788401423276', 7.25, 504, '2000-01-01', 6, 4, 10, 1, 8, 7),
  183.     (DEFAULT, 'Las enseñanzas de Don Juan', '9788499892627', 7.45, 288, '1968-01-01', 3, 9, 2, 5, 6, 4),
  184.     (DEFAULT, 'Los versos satánicos', '9788490628770', 7.15, 576, '1988-09-26', 9, 5, 1, 8, 7, 3),
  185.     (DEFAULT, 'Crónica de una muerte anunciada', '9788490628787', 7.30, 128, '1981-01-01', 2, 6, 10, 7, 4, 1),
  186.     (DEFAULT, 'La naranja mecánica', '9788401352247', 7.60, 240, '1962-01-01', 1, 8, 6, 9, 2, 10);
  187.  
Add Comment
Please, Sign In to add comment