Está en la página 1de 4

create table edicion(

cod_edicion number(50) not null,


nombre varchar2(50) not null);
create sequence cod_edicion minvalue 1 start with 1 cache 900000;

create table idioma(


cod_idioma number(50) not null primary key,
nombre varchar2(50) not null);
create sequence cod_idioma minvalue 1 start with 1 cache 900000;

create table editorial(


cod_editorial number(50) not null primary key,
descripcion varchar2(50) not null);
create sequence cod_editorial minvalue 1 start with 1 cache 900000;

create table volumen(


cod_volumen number(50) not null primary key,
descripcion varchar2(50) not null);
create sequence cod_volumen minvalue 1 start with 1 cache 900000;

create table area(


cod_area number(50) not null primary key,
nombre varchar2 (50) not null );
create sequence cod_area minvalue 1 start with 1 cache 900000;

create table pais(


cod_pais number(50) not null primary key,
nombre varchar2(50) not null);
create sequence cod_pais minvalue 1 start with 1 cache 900000;

create table estado(


cod_estado number(50) not null primary key,
descripcion varchar2(50) not null);
create sequence cod_estado minvalue 1 start with 1 cache 900000;

create table carrera(


cod_carrera number(50) not null primary key,
nombre varchar2(50) not null);
create sequence cod_carrera minvalue 1 start with 1 cache 900000;

create table presenta(


cod_presentacion number(50) not null primary key,
descripcion varchar2(50) not null);
create sequence cod_presenta minvalue 1 start with 1 cache 900000;

create table dano(


cod_dano number(50) primary key,
descripcion varchar2(50),
valor float(15));
create sequence cod_dano minvalue 1 start with 1 cache 900000;

create table autor(


cod_autor number(50) not null primary key,
nombre varchar2(50) not null,
fecha_nacimiento date not null,
cod_pais number(50) not null,
foreign key (cod_pais) references pais (cod_pais));
create sequence cod_autor minvalue 1 start with 1 cache 900000;
create table estudiante(
cod_estudiante number(50) not null primary key,
cedula int(15) not null,
nombre varchar2(50) not null,
p_apellido varchar2(50) not null,
s_apellido varchar2(50) not null,
direccion varchar2(50) not null,
fecha_nacimiento date not null,
cod_carrera number(50) not null,
foreign key (cod_carrera) references carrera (cod_carrera));
create sequence cod_estudiante minvalue 1 start with 1 cache 900000;

create table libro(


cod_libro number(50) not null primary key,
nombre varchar2(50) not null,
cod_area number(50) not null,
cod_edicion number(50) not null,
cod_idioma number(50) not null,
cod_volumen number(50) not null,
cod_editorial number(50) not null,
cod_presentacion number(50) not null,
cod_autor number(50) not null,
foreign key (cod_autor) references autor (cod_autor),
foreign key (cod_area) references area (cod_area),
foreign key (cod_edicion) references edicion (cod_edicion),
foreign key (cod_idioma) references idioma (cod_idioma),
foreign key (cod_volumen) references volumen (cod_volumen),
foreign key (cod_editorial) references editorial (cod_editorial),
foreign key (cod_presentacion) references presenta (cod_presentacion));
create sequence cod_libro minvalue 1 start with 1 cache 900000;

create table libro_autor(


cod_libro number(50) not null,
cod_autor number(50) not null,
foreign key (cod_libro) references libro (cod_libro),
foreign key (cod_autor) references autor (cod_autor));

create table prestamo(


cod_prestamo number(50) not null primary key,
fecha_prestamo date not null,
fecha_devolucion date not null,
cod_estudiante number(50) not null,
cod_libro number(50) not null,
cod_estado number(50) not null,
cod_dano number(50),
foreign key (cod_estado) references estado(cod_estado),
foreign key (cod_libro) references libro (cod_libro),
foreign key (cod_estudiante) references estudiante (cod_estudiante),
foreign key (cod_dano) references dano (cod_dano));
create sequence cod_prestamo minvalue 1 start with 1 cache 900000;

insert into dano (descripcion) values ('total'),('parcial');


insert into presenta (descripcion) values ('grueso'),('delgado'),('mediano'),
('ancho'),('extralargo');
insert into area (nombre) values ('matematica'),('ciencias'),('biologia'),
('fisica'),('quimica');
insert into idioma (nombre) values ('español'),('ingles'),('aleman'),('portuges'),
('frances'),('mandarin');
insert into edicion (nombre) values ('rojo'),('negro'),('verde'),('azul'),
('blanco');
insert into carrera (nombre) values ('ingenieria'),('medicina'),('economia'),
('lenguas'),('abogado');
insert into editorial (descripcion) values ('feliz'),('triste'),('bravo'),
('contento'),('confundido');
insert into volumen (descripcion) values ('I'),('II'),('III'),('IV'),('V');
insert into pais (nombre) values ('colombia'),('ecuador'),('peru'),('brazil'),
('japon'),('argentina');
insert into autor (nombre,fecha_nacimiento,cod_pais) values ('camilo','1990-12-
1',1),('andres','1996-05-28',2),('fabiola','1980-01-20',3),('tatiana','2015-10-
10',4),('kira','2001-02-18',5);
insert into estudiante
(cedula,nombre,p_apellido,s_apellido,direccion,fecha_nacimiento,cod_carrera) values
('1030666287','felipe','merchan','diaz','carrera 80 # 8c -85','1996-05-28',1)
,('51952524','maria','diaz','higuita','carrera 73 a bis#38 c - 54 sur','1961-01-
23',2),('19482418','william','rojas','rodriguez','calle 8 #34-54','1971-02-22',3),
('12345567','angie','sanchez','rodriguez','diagonal 8 # 34f-54','1993-02-30',4),
('98765432123','monica','lozano','cubides','carrera 23 #29-03','1994-06-23',5);

insert into libro


(nombre,cod_area,cod_edicion,cod_idioma,cod_volumen,cod_editorial,cod_presentacion,
cod_autor) values ('it',1,2,1,3,4,2,5),('los niños del maiz',2,3,4,5,1,2,3),
('automoviles',1,3,4,2,1,4,5),('el resplandor',2,1,3,5,4,3,4),('el
reino',2,3,4,1,4,5,3);

insert into estado (descripcion) values ('devuelto'),('prestado');

insert into prestamo


(fecha_prestamo,fecha_devolucion,cod_estudiante,cod_libro,cod_estado,cod_dano)
values ('2019-10-20','2019-10-21',1,2,1,2),('2019-02-1','2019-03-29',2,3,2,1),
('2018-05-28','2018-10-23',3,1,1,2),
('2019-06-02','2019-06-30',4,5,2,1),('2017-04-22','2017-10-29',5,4,2,2);

alter table libro add Valor float (15) NOT NULL;


alter table libro add Years number(5) NOT NULL;

update libro set Valor=2000, Years=1980 where cod_libro=1;


update libro set Valor=3000, Years=1987 where cod_libro=2;
update libro set Valor=4000, Years=1989 where cod_libro=3;
update libro set Valor=5000, Years=1990 where cod_libro=4;
update libro set Valor=6000, Years=1992 where cod_libro=5;
update dano set valor=2000 where cod_dano=1;
update dano set valor=5000 where cod_dano=2;

consultas:
select cod_autor,nombre,cod_pais from autor;

select nombre from estudiante;

SELECT p_apellido from estudiante order by p_apellido;


select nombre from autor where cod_pais='1';

select nombre from autor where cod_pais='4' or cod_pais='5';

select cod_area, nombre from libro where cod_area='4' or cod_area='5' or


cod_autor='3';

select e.nombre,e.p_apellido,e.s_apellido, year(curdate())-year(e.fecha_nacimiento)


+if(date_format(curdate(),'%m-%d')> date_format(e.fecha_nacimiento,'%m-%d'),0,-1)
as edad from estudiante e;

select p_apellido from estudiante where p_apellido like 'm%';

select cod_estudiante, cod_estado,cod_libro from prestamo where cod_estado=2;

select * from libro where Valor BETWEEN 2000 and 4000

select nombre , years, valor from libro where valor > 3000

select e.cod_estudiante,e.nombre,e.p_apellido,c.nombre from estudiante e,carrera c


where e.cod_carrera=c.cod_carrera

revisar:
SELECT e.cod_estudiante , p.cod_estado,e.nombre,l.nombre,l.cod_libro from prestamo
p inner join estudiante e on e.cod_estudiante=p.cod_estudiante inner join libro l
on l.cod_libro=p.cod_libro where p.cod_estado=2 ;

También podría gustarte