Script Biblioteca base de datos.
Jairo ArtistInforme23 de Marzo de 2016
1.018 Palabras (5 Páginas)249 Visitas
Create database bibliotecaaa;
Use bibliotecaaa;
CREATE TABLE IF NOT EXISTS `genero` (
`id_genero` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`denominacion` varchar(50) NOT NULL,
PRIMARY KEY(id_genero)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `imagenes` (
`id_imagen` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`nombre` varchar(50),
`imagen` longblob,
PRIMARY KEY(id_imagen)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `imagenpais` (
`id_imagenPais` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`nombre` varchar(50),
`imagen` longblob,
PRIMARY KEY(id_imagenPais)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `tipodocumento` (
`id_tipoDoc` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`denominacion` varchar(50),
`Descripcion` varchar(50),
PRIMARY KEY(id_tipoDoc)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `tipoprestamo` (
`id_tipoPrestamo` int(2) unsigned zerofill NOT NULL AUTO_INCREMENT,
`denominacion` varchar(50),
PRIMARY KEY(id_tipoPrestamo)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `tipousuario` (
`id_tipoUsuario` int(2) unsigned zerofill NOT NULL AUTO_INCREMENT,
`denominacion` varchar(50),
PRIMARY KEY(id_tipoUsuario)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `ubicacion` (
`id_ubicacion` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`ubicacion` varchar(50) NOT NULL,
PRIMARY KEY(id_ubicacion)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `imageneslibros` (
`idImagen` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`imagen` longblob,
`nombre` varchar(30),
PRIMARY KEY(idImagen)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `paises` (
`id_pais` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`nombrePais` varchar(50) NOT NULL,
`id_imagenPais` int(4) unsigned zerofill NULL,
PRIMARY KEY(id_pais),
INDEX(id_imagenPais),
FOREIGN KEY(id_imagenPais)REFERENCES imagenpais(id_imagenPais)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `autor` (
`id_autor` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`nombres` varchar(50),
`apellido1` varchar(20),
`apellido2` varchar(20)NULL,
`id_pais` int(4) unsigned zerofill NOT NULL,
PRIMARY KEY(id_autor),
INDEX(id_pais),
FOREIGN KEY(id_pais)REFERENCES paises(id_pais)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `editorial` (
`id_editorial` int(3) unsigned zerofill NOT NULL AUTO_INCREMENT,
`nombre` varchar(50),
`paisEditorial` int(4) unsigned zerofill NOT NULL,
PRIMARY KEY(id_editorial),
INDEX(paisEditorial),
FOREIGN KEY(paisEditorial)REFERENCES paises(id_pais)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `libros` (
`id_libro` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`titulo` varchar(50),
`tomo` int(2),
`id_editorial` int(3) unsigned zerofill NOT NULL,
`numEdicion` int(3),
`añoEdicion` int(4),
`id_genero` int(3) unsigned zerofill NOT NULL,
`isbn` bigint(13),
`numPaginas` int(4),
`fechaRegistro` date,
`formato` varchar(100),
`idImagen` int(3) unsigned zerofill NULL,
PRIMARY KEY(id_libro),
INDEX(id_editorial, id_genero),
FOREIGN KEY(id_editorial)REFERENCES editorial(id_editorial),
FOREIGN KEY(id_genero)REFERENCES genero(id_genero),
FOREIGN KEY(idImagen)REFERENCES imageneslibros(idImagen)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `autoresporlibro` (
`id_autor` int(3) unsigned zerofill NOT NULL,
`id_libro` int(4) unsigned zerofill NOT NULL,
PRIMARY KEY(id_autor, id_libro),
INDEX(id_autor, id_libro),
FOREIGN KEY(id_autor)REFERENCES autor(id_autor),
FOREIGN KEY(id_libro)REFERENCES libros(id_libro)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `copiasporlibro` (
`SecuenciaCopXLibro` int(4) NOT NULL AUTO_INCREMENT,
`id_libro` int(4) unsigned zerofill NOT NULL,
`Copia` int(3),
`prestado` varchar(2),
`id_ubicacion` int(3) unsigned zerofill NOT NULL,
PRIMARY KEY(SecuenciaCopXLibro),
INDEX(id_libro, id_ubicacion),
FOREIGN KEY(id_libro)REFERENCES libros(id_libro),
FOREIGN KEY(id_ubicacion)REFERENCES ubicacion(id_ubicacion)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `usuario` (
`id_usuario` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`id_tipoUsuario` int(3) unsigned zerofill NOT NULL,
`nombres` varchar(50),
`apellido1` varchar(50),
`apellido2` varchar(50)NULL,
`id_tipoDoc` int(3) unsigned zerofill NOT NULL,
`numDoc` varchar(10),
`numTelefono` varchar(20),
`DOMICILIO` varchar(50),
`id_imagen` int(4) unsigned zerofill NULL,
`estado` varchar(10),
PRIMARY KEY(id_usuario),
INDEX(id_tipoUsuario, id_tipoDoc, id_imagen),
FOREIGN KEY(id_tipoUsuario)REFERENCES tipousuario(id_tipoUsuario),
FOREIGN KEY(id_tipoDoc)REFERENCES tipodocumento(id_tipoDoc),
FOREIGN KEY(id_imagen)REFERENCES imagenes(id_imagen)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `prestamo` (
`id_prestamo` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
`id_usuario` int(3) unsigned zerofill NOT NULL,
`referCopiasPorLibro` int(4) NOT NULL,
`id_tipoPrestamo` int(3) unsigned zerofill NOT NULL,
`fechaSalida` VARCHAR(10) NOT NULL,
`fechaEntrega` VARCHAR(10) NOT NULL,
PRIMARY KEY(id_prestamo),
INDEX(id_usuario, referCopiasPorLibro, id_tipoPrestamo),
FOREIGN KEY(id_usuario)REFERENCES usuario(id_usuario),
FOREIGN KEY(referCopiasPorLibro)REFERENCES copiasporlibro(SecuenciaCopXlibro),
FOREIGN KEY(id_tipoPrestamo)REFERENCES tipoprestamo(id_tipoPrestamo)
) ENGINE=InnoDB;
INSERT INTO `genero` (`id_genero`, `denominacion`) VALUES
(001, 'Ciencias'),
(002, 'Matematicas'),
(003, 'Computacion'),
(004, 'Universitarios');
INSERT INTO `tipodocumento` (`id_tipoDoc`, `denominacion`, `Descripcion`) VALUES
(001, 'DUE', 'Documento Unico Estudiantil'),
(002, 'DUI', 'Documento Unico de Identidad'),
(003, 'CE', 'Carnet Estudiantil');
INSERT INTO `tipoprestamo` (`id_tipoPrestamo`, `denominacion`) VALUES
(01, 'Interno'),
(02, 'Externo');
INSERT INTO `tipousuario` (`id_tipoUsuario`, `denominacion`) VALUES
(01, 'Estudiante'),
(02, 'Docente'),
(03, 'Particulares');
INSERT INTO `ubicacion` (`id_ubicacion`, `ubicacion`) VALUES
(001, 'Modulo 1'),
(002, 'Modulo 2'),
(003, 'Modulo 3'),
(004, 'Modulo 4');
INSERT INTO `paises` (`id_pais`, `nombrePais`) VALUES
(0001, 'Mexico'),
(0002, 'Inglaterra'),
(0003, 'Estados Unidos'),
(0004, 'España');
INSERT INTO `editorial` (`id_editorial`, `nombre`, `paisEditorial`) VALUES
(001, 'PEARSON', 0001),
(002, 'MAPASA S.A DE C.V', 0001),
(003, 'MAPEX EDITORIAL', 0004);
INSERT INTO `imageneslibros` (`idImagen`, `imagen`, `nombre`) VALUES
...