Sei sulla pagina 1di 6

create database Bilioteca;

use Biblioteca;
CREATE TABLE `autor` (
`IdAutor` int(11) NOT NULL,
`Nombre` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Alias` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Pais` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `bibliografia` (
`IdBibliografia` int(11) NOT NULL,
`Titulo` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Edicion` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Editorial` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Resumen` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Estado` datetime DEFAULT NULL,
`IdTBibliografia` int(11) DEFAULT NULL,
`IdMateria` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `bibliotecario` (
`IdBibliotecario` int(11) NOT NULL,
`Apellidos` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Nombres` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`DNI` int(8) DEFAULT NULL,
`Genero` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`FechaNac` date DEFAULT NULL,
`Direccion` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Telefono` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Email` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Estado` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `carnet` (
`IdCarnet` int(11) NOT NULL,
`FechaEmision` date DEFAULT NULL,
`FechaVencimiento` date DEFAULT NULL,
`Estado` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`IdLector` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `detalle_autor` (
`IdDAutor` int(11) NOT NULL,
`IdBibliografia` int(11) DEFAULT NULL,
`IdAutor` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `detalle_prestamo` (
`IdDPrestamo` int(11) NOT NULL,
`FechaDevolucion` date DEFAULT NULL,
`Estado` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`IdPrestamo` int(11) DEFAULT NULL,
`IdBibliografia` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `detalle_turno` (
`IdDTurno` int(11) NOT NULL,

`FechaTurno` datetime DEFAULT NULL,


`IdTurno` int(11) DEFAULT NULL,
`IdBibliotecario` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `lector` (
`IdLector` int(11) NOT NULL,
`IdTipoLector` int(11) NOT NULL,
`Apellidos` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Nombres` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`DNI` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Genero` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`FechaNac` date DEFAULT NULL,
`Direccion` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Telefono` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Email` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `materia` (
`IdMateria` int(11) NOT NULL,
`nombre` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `prestamo` (
`IdPrestamo` int(11) NOT NULL,
`FechaPrestamo` date DEFAULT NULL,
`Estado` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Cantidad` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`FechaAnulacion` date DEFAULT NULL,
`IdCarnet` int(11) DEFAULT NULL,
`IdBibliotecario` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `sesion` (
`IdSesion` int(11) NOT NULL,
`FechaInicio` datetime DEFAULT NULL,
`FechaFin` datetime DEFAULT NULL,
`IdUsuario` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `tipo_bibliografia` (
`IdTBibliografia` int(11) NOT NULL,
`nombre` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;

CREATE TABLE `tipo_lector` (


`IdTipoLector` int(11) NOT NULL,
`nombre` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `turno` (
`IdTurno` int(11) NOT NULL,
`Nombre` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,

`HoraInicio` time DEFAULT NULL,


`HoraFIn` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
CREATE TABLE `usuario` (
`IdUsuario` int(11) NOT NULL,
`Username` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Password` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`Estado` varchar(50) COLLATE utf8_spanish_ci DEFAULT NULL,
`IdLector` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
ALTER TABLE `autor`
ADD PRIMARY KEY (`IdAutor`);
ALTER
ADD
ADD
ADD

TABLE `bibliografia`
PRIMARY KEY (`IdBibliografia`),
KEY `IdTBibliografia` (`IdTBibliografia`),
KEY `IdMateria` (`IdMateria`);

ALTER TABLE `bibliotecario`


ADD PRIMARY KEY (`IdBibliotecario`);
ALTER TABLE `carnet`
ADD PRIMARY KEY (`IdCarnet`),
ADD KEY `IdLector` (`IdLector`);
ALTER
ADD
ADD
ADD

TABLE `detalle_autor`
PRIMARY KEY (`IdDAutor`),
KEY `IdBibliografia` (`IdBibliografia`),
KEY `IdAutor` (`IdAutor`);

--- Indices de la tabla `detalle_prestamo`


-ALTER TABLE `detalle_prestamo`
ADD PRIMARY KEY (`IdDPrestamo`),
ADD KEY `IdPrestamo` (`IdPrestamo`),
ADD KEY `IdBibliografia` (`IdBibliografia`);
--- Indices de la tabla `detalle_turno`
-ALTER TABLE `detalle_turno`
ADD PRIMARY KEY (`IdDTurno`),
ADD KEY `IdTurno` (`IdTurno`),
ADD KEY `IdBibliotecario` (`IdBibliotecario`);
--- Indices de la tabla `lector`
-ALTER TABLE `lector`
ADD PRIMARY KEY (`IdLector`);
ALTER TABLE `materia`
ADD PRIMARY KEY (`IdMateria`);
ALTER TABLE `prestamo`
ADD PRIMARY KEY (`IdPrestamo`),

ADD KEY `IdCarnet` (`IdCarnet`),


ADD KEY `IdBibliotecario` (`IdBibliotecario`);
ALTER TABLE `sesion`
ADD PRIMARY KEY (`IdSesion`),
ADD KEY `IdUsuario` (`IdUsuario`);
ALTER TABLE `tipo_bibliografia`
ADD PRIMARY KEY (`IdTBibliografia`);
ALTER TABLE `tipo_lector`
ADD PRIMARY KEY (`IdTipoLector`);
ALTER TABLE `turno`
ADD PRIMARY KEY (`IdTurno`);
ALTER TABLE `usuario`
ADD PRIMARY KEY (`IdUsuario`),
ADD KEY `IdLector` (`IdLector`);
ALTER TABLE `autor`
MODIFY `IdAutor` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
ALTER TABLE `bibliografia`
MODIFY `IdBibliografia` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `bibliotecario`
MODIFY `IdBibliotecario` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
ALTER TABLE `carnet`
MODIFY `IdCarnet` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;
ALTER TABLE `detalle_autor`
MODIFY `IdDAutor` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `detalle_prestamo`
MODIFY `IdDPrestamo` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
ALTER TABLE `detalle_turno`
MODIFY `IdDTurno` int(11) NOT NULL AUTO_INCREMENT;
--- AUTO_INCREMENT de la tabla `lector`
-ALTER TABLE `lector`
MODIFY `IdLector` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;
--- AUTO_INCREMENT de la tabla `materia`
-ALTER TABLE `materia`
MODIFY `IdMateria` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=24;
--- AUTO_INCREMENT de la tabla `prestamo`
-ALTER TABLE `prestamo`
MODIFY `IdPrestamo` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;
--- AUTO_INCREMENT de la tabla `sesion`
-ALTER TABLE `sesion`
MODIFY `IdSesion` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--- AUTO_INCREMENT de la tabla `tipo_bibliografia`


-ALTER TABLE `tipo_bibliografia`
MODIFY `IdTBibliografia` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
--- AUTO_INCREMENT de la tabla `tipo_lector`
-ALTER TABLE `tipo_lector`
MODIFY `IdTipoLector` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=31;
--- AUTO_INCREMENT de la tabla `turno`
-ALTER TABLE `turno`
MODIFY `IdTurno` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--- AUTO_INCREMENT de la tabla `usuario`
-ALTER TABLE `usuario`
MODIFY `IdUsuario` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
ALTER TABLE `bibliografia`
ADD CONSTRAINT `bibliografia_ibfk_1` FOREIGN KEY (`IdTBibliografia`) REFERENCE
S `tipo_bibliografia` (`IdTBibliografia`),
ADD CONSTRAINT `bibliografia_ibfk_2` FOREIGN KEY (`IdMateria`) REFERENCES `mat
eria` (`IdMateria`);
ALTER TABLE `carnet`
ADD CONSTRAINT `carnet_ibfk_1` FOREIGN KEY (`IdLector`) REFERENCES `lector` (`
IdLector`);
ALTER TABLE `detalle_autor`
ADD CONSTRAINT `detalle_autor_ibfk_1` FOREIGN KEY (`IdBibliografia`) REFERENCE
S `bibliografia` (`IdBibliografia`),
ADD CONSTRAINT `detalle_autor_ibfk_2` FOREIGN KEY (`IdAutor`) REFERENCES `auto
r` (`IdAutor`);
ALTER TABLE `detalle_prestamo`
ADD CONSTRAINT `detalle_prestamo_ibfk_1` FOREIGN KEY (`IdPrestamo`) REFERENCES
`prestamo` (`IdPrestamo`),
ADD CONSTRAINT `detalle_prestamo_ibfk_2` FOREIGN KEY (`IdBibliografia`) REFERE
NCES `bibliografia` (`IdBibliografia`);
ALTER TABLE `detalle_turno`
ADD CONSTRAINT `detalle_turno_ibfk_1` FOREIGN KEY (`IdTurno`) REFERENCES `turn
o` (`IdTurno`),
ADD CONSTRAINT `detalle_turno_ibfk_2` FOREIGN KEY (`IdBibliotecario`) REFERENC
ES `bibliotecario` (`IdBibliotecario`);
ALTER TABLE `prestamo`
ADD CONSTRAINT `prestamo_ibfk_1` FOREIGN KEY (`IdCarnet`) REFERENCES `carnet`
(`IdCarnet`),
ADD CONSTRAINT `prestamo_ibfk_2` FOREIGN KEY (`IdBibliotecario`) REFERENCES `b
ibliotecario` (`IdBibliotecario`);
ALTER TABLE `sesion`
ADD CONSTRAINT `sesion_ibfk_1` FOREIGN KEY (`IdUsuario`) REFERENCES `usuario`

(`IdUsuario`);
ALTER TABLE `usuario`
ADD CONSTRAINT `usuario_ibfk_1` FOREIGN KEY (`IdLector`) REFERENCES `lector` (
`IdLector`);
ALTER TABLE `lector`
ADD CONSTRAINT `_tipolector` FOREIGN KEY (`IdTipolector`) REFERENCES `tipo_lec
tor` (`IdTipoLector`);