0% encontró este documento útil (0 votos)
53 vistas3 páginas

Practica 5 Base de Datos

El documento crea una base de datos BIBLIOFCAV con tablas para libros, autores, prestamos de libros y estudiantes. Se insertan registros de ejemplo en cada tabla y se establecen relaciones entre ellas mediante claves primarias y foráneas. También se muestran instrucciones para modificar las tablas, como agregar y eliminar columnas y cambiar tipos de datos.

Cargado por

Eduardo Martinez
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
53 vistas3 páginas

Practica 5 Base de Datos

El documento crea una base de datos BIBLIOFCAV con tablas para libros, autores, prestamos de libros y estudiantes. Se insertan registros de ejemplo en cada tabla y se establecen relaciones entre ellas mediante claves primarias y foráneas. También se muestran instrucciones para modificar las tablas, como agregar y eliminar columnas y cambiar tipos de datos.

Cargado por

Eduardo Martinez
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 3

Create database BIBLIOFCAV

USE BIBLIOFCAV

Create table LIBRO


(Id_libro int primary key not null,
Titulo char(20) null,
Editorial char(15) null,
Area char(14) null)

Select * from LIBRO

Insert into LIBRO


Values ('001', 'Shurima', 'CDMX','Internet')

Insert into LIBRO


Values ('002','Runaterra','Cualquiera','Internet')

Insert into LIBRO


Values ('003','Harry Potter','JK Rowling','Fantasia')

Insert into LIBRO


Values ('004', 'Lago Ness', 'Pearson', 'Naturaleza')

Insert into LIBRO


Values ('005', 'El Sol','NASA', 'Ciencia')

Insert into LIBRO


Values ('006','El cuerpo', 'Nat Geo', 'Biologia')

--- MOSTRAR CONTENIDO DE LA TABLA


Select * from LIBRO

Create table AUTOR


(Id_autor int primary key not null,
Nombre char(10) null,
Nacionalidad varchar(18) null)

Select * from AUTOR

Insert into AUTOR


Values ('1','Trejo', 'USA')

Insert into AUTOR


Values ('2','Lee', 'CHINA')

Insert into AUTOR


Values ('3','Andrea', 'ITALIA')

Insert into AUTOR


Values ('4','Kojima', 'JAPON')

Insert into AUTOR


Values ('5','William', 'CANADA')

Insert into AUTOR


Values ('6','Carlos', 'ARGENTINA')
Select* from AUTOR

Create table LIBAUT


(Id_Libaut char(5) primary key not null,
Id_autor int foreign key references AUTOR,
Id_libro int foreign key references LIBRO)

Select* from LIBAUT


Insert into LIBAUT
Values ('a','1','001')

Insert into LIBAUT


Values('b','2','002')

Insert into LIBAUT


Values('c','3','003')

Insert into LIBAUT


Values('d','4','004')

Insert into LIBAUT


Values('e','5','005')

Insert into LIBAUT


Values('f','6','006')

Create table ESTUDIANTE


(Id_lector int primary key not null,
Nombre char(23) null,
Direccion char(50) null,
Carrera varchar(40) null,
Edad int null)

Select* from ESTUDIANTE


Insert into ESTUDIANTE
Values ('100','Jose','calle 22','informatica','21')
Insert into ESTUDIANTE
Values ('200','Ferando','calle 23','informatica','16')
Insert into ESTUDIANTE
Values ('300','Cesar','calle 2','informatica','19')
Insert into ESTUDIANTE
Values ('400','Juan','calle 4','contador','17')
Insert into ESTUDIANTE
Values ('500','Carlos','calle 39','contador','18')
Insert into ESTUDIANTE
Values ('600','Ana','calle 44','administracion','19')

Create table PRESTAMO


(Id_Prestamo int primary key not null,
Id_lector int foreign key references ESTUDIANTE,
Id_libro int foreign key references LIBRO,
Fechaprestamo date not null,
Fechadevolucion date null,
Devuelto varchar(5) null)

Select* from PRESTAMO


Insert into PRESTAMO
Values('10','100','001','2021-10-12','2021-10-12','SI')
Insert into PRESTAMO
Values('20','200','002','2021-10-13','2021-10-29','NO')
Insert into PRESTAMO
Values('30','300','003','2021-10-14','2021-10-18','NO')
Insert into PRESTAMO
Values('40','400','004','2021-10-12','2021-10-27','SI')
Insert into PRESTAMO
Values('50','500','005','2021-10-11','2021-10-26','NO')
Insert into PRESTAMO
Values('60','600','006','2021-10-03','2021-10-24','SI')

--- utilizacion de varias instrucciones

---instruccion para agregar columnas a mi tabla


Alter table ESTUDIANTE
Add SEXO char null

Alter table LIBRO


Add IDIOMA char(15) null

Select*from ESTUDIANTE

---instruccion para borrar una columna de mi tabla


Alter table ESTUDIANTE
Drop column SEXO

---instruccion para cambiar el tipo de dato de mi columna o campo


Alter table ESTUDIANTE
Alter column CARRERA char(30) null

Create table ESTUDIANTE2


(
Id_lector int not null,
Id_Libaut char(5) null,
Nombre char(23) null,
Direccion char(50) null,
Carrera varchar(40) null,
Edad int null)

--Instruccion que permite asignar la llave primaria


alter table ESTUDIANTE2
add primary key (Id_lector)

---Borrar una tabla


drop table ESTUDIANTE2

Select*from ESTUDIANTE2

--Instruccion para asignar la llave foranea


alter table ESTUDIANTE2
Add foreign key (Id_Libaut) references LIBAUT (Id_Libaut);

También podría gustarte