Вы находитесь на странице: 1из 14

Create procedure insertarProfesor(docprof varchar(11), nomprof varchar(30), apeprof varchar(30),

cateprof int, salprof int)

Insert into Profesor(docprof, nomprof, apeprof, cateprof, salprof) values (docprof, nomprof,
apeprof, cateprof, salprof);

Call insertarProfesor('23456789', 'Edwin', 'Rodriguez', 1, 780000);

Call insertarProfesor('63502720', 'Marta', 'Rojas', 2, 690000);

Call insertarProfesor('91216904', 'Carlos', 'Perez', 3, 950000);

Call insertarProfesor('13826789', 'Maritza', 'Angarita', 1, 550000);

Call insertarProfesor('1098765789', 'Alejandra', 'Torres', 4, 1100000);

Call insertarProfesor('91500128', 'Luis', 'Mayorga', 5, 2500000);

Create procedure insertarCurso(Codcurs int(15), nomcurs varchar(100), horascur int, valorcur int)

Insert into Curso(Codcurs, nomcurs, horascur, valorcur) values (Codcurs, nomcurs, horascur,
valorcur);

Call insertarCurso('149842', 'Fundamentos de Base de Datos', 40, 500000);

Call insertarCurso('250067', 'Fundamentos de SQL',20, 700000);

Call insertarCurso('289011', 'Manejo de Mysql', 45, 550000);

Call insertarCurso('345671', 'Fundamentals of Oracle', 60, 3000000);

Call insertarCurso('190087', 'Fundamentos de Linux', 40, 850000);

Create procedure insertarEstudiante(Docest varchar(11), nomest varchar(30), apeest varchar(30),


edadest int)

Insert into Estudiante(Docest, nomest , apeest, edadest) values (Docest, nomest , apeest,
edadest);

Call insertarEstudiante('14984200', 'Carlos', 'Torres', 35);

Call insertarEstudiante('63569002', 'Maria', 'Mayorga', 25);


Create table estudiante (

-> docest varchar (11) not null,

-> nomest varchar (30) not null,

-> apeest varchar (30) not null,

-> edadest int not null,

-> primary key (docest)

->

-> );

Field | Type | Null | Key | Default | Extra |

+----------+--------------+------+-----+---------+----------------+

| Codcurs | int(15) | NO | PRI | NULL | auto_increment |

| nomcurs | varchar(100) | NO | | NULL | |

| horascur | int(11) | NO | | NULL | |

| valorcur | int(11) | NO | | NULL | |

+----------+--------------+------+-----+---------+----------------+

create table Estudiantexcurso (

codcur_estcur int (15),

docest_estcur varchar (11),

fecini_estcur Date not null,

foreign key (codcur_estcur) references curso(Codcurs),

foreign key (docest_estcur) references estudiante(docest)

);
Create procedure insertarEstudiantexcurso(Codcur_estcur int(15), docest_estcur varchar(11),
fecini_estcur Date)

Insert into Estudiantexcurso(Codcur_estcur, docest_estcur, fecini_estcur) values (Codcur_estcur,


docest_estcur, fecini_estcur);

Call insertarEstudiantexcurso(289011, '1098765678', '2011-02-01');

Call insertarEstudiantexcurso(250067, '63502720', '2011-03-01');

Call insertarEstudiantexcurso(289011, '1098098097', '2011-02-01');

Call insertarEstudiantexcurso(345671, '63502720', '2011-04-01');

Call insertarEstudiantexcurso(345671, '63502720', '2011-04-01');


Create procedure insertarCompañia(Comnit varchar(11), connombre varchar(30), comañofun
int(11), comreplegal varchar(100))

Insert into Compañia(Comnit , connombre, comañofun, comreplegal) values (Comnit, connombre,


comañofun, comreplegal);

Call insertarCompañia('800890891 1', 'Seguros Lemuria', 2018, 'Erick Vera');

Create procedure insertarTiposautomotores(auttipo int(11), autnombre varchar(30))

Insert into Tiposautomotores(auttipo, autnombre) values (auttipo, autnombre);

Call insertarTiposautomotores(4, 'Deportivo');

Create procedure insertarAutomotores(autoplaca varchar(6), automarca varchar(30), autotipo


int(11), automodelo int(11), autonumpasajeros int(11), autocilindraje int(11), autonumchasis
varchar (20))

Insert into Automotores(autoplaca, automarca, autotipo, automodelo, autonumpasajeros,


autocilindraje, autonumchasis) values (autoplaca, automarca, autotipo, automodelo,
autonumpasajeros, autocilindraje, autonumchasis);

Call insertarAutomotores('EJC325', 'Chevrolet Camaro', 4, 2018, 5, 2500, 'wywzzz145kk09d18');

Create procedure insertarAseguramientos(asecodigo int(11), asefechainicio date,


asefechaexpiracion date, asevalorasegurado int (11), aseestado varchar(30), asecosto int(11),
aseplaca varchar (20))

Insert into Aseguramientos(asecodigo, asefechainicio , asefechaexpiracion, asevalorasegurado,


aseestado, asecosto, aseplaca) values(asecodigo, asefechainicio , asefechaexpiracion,
asevalorasegurado, aseestado, asecosto, aseplaca);

Call insertarAseguramientos(4, '2018-01-01','2018-12-31', 10000000, 'Vigente', 1000000, 'EJC325');


Create procedure insertarIncidentes2(incicodigo int(11), incifecha date, inciplaca varchar (6),
incilugar varchar(40), incicantheridos int(11), incicanfatalidades int (11), incicanautosinvolucrados
int(11))

Insert into Incidentes(incicodigo, incifecha, inciplaca, incilugar, incicantheridos, incicanfatalidades,


incicanautosinvolucrados) values(incicodigo, incifecha, inciplaca, incilugar, incicantheridos,
incicanfatalidades, incicanautosinvolucrados);

Call insertarIncidentes2(5, '2018-02-15','EJC325', 'Barrancabermeja', 0, 0, 2);

Create procedure ordenamientovalor()

Select Codcurs, nomcurs, horascur, valorcur from Curso order by valorcur;

Call ordenamientovalor();

Insert into ArticuloxPedido


(idped_artped,idart_artped,canart_artped,valven_artped) values
(1,3,5,'40000'),
(1,4,12,'55000'),
(2,1,5,'65000'),
(3,2,10,'55000'),
(3,3,12,'45000'),
(4,1,20,'65000');
Select * from ArticuloxPedido;

describe articuloxpedido;

+---------------+---------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------------+---------+------+-----+---------+-------+

| idped_artped | int(11) | NO | PRI | NULL | |

| idart_art | int(11) | NO | | NULL | |

| canart_artped | int(11) | NO | | NULL | |

| valven_artped | int(11) | NO | | NULL | |

Create procedure insertarArticuloxpedido3(idped_artped int(11), idart_artped int(11),


canart_artped int(11), valven_artped int(11))
Insert into Articuloxpedido(idped_artped, idart_artped, canart_artped, valven_artped)
values(idped_artped, idart_artped, canart_artped, valven_artped);

Call insertarArticuloxpedido3(1, 3, 5, 40000);

Call insertarArticuloxpedido3(1, 4, 12, 55000);

Call insertarArticuloxpedido3(2, 1, 5, 65000);

Call insertarArticuloxpedido3(3, 2, 10, 55000);

Call insertarArticuloxpedido3(3, 3, 12, 45000);

Call insertarArticuloxpedido3(4, 1, 20, 65000);

Create procedure articuloxpedido()

Select , nomcurs, horascur, valorcur from Curso order by valorcur;

Call ordenamientovalor();

create table ArticuloxPedido (


idped_artped int (11)not null,
idart_artped int (11)not null,
canart_artped int (11)not null,
valven_artped int (11)not null,
foreign key (idped_artped) references Articulo (id_art)
);

Create procedure detallepedido()

Select id_ped, tit_art, canart_artped, valven_artped from pedido

Inner join articuloxpedido on idped_artped = id_ped

Inner join articulo on id_art = idart_artped;

Call detallepedido();

Create procedure verempresas()

Select*from compañia

where comañofun <= 1998 and comañofun >= 1991;

Call verempresas();
Create procedure verclientesordenalfabetico()

Select*from cliente order by ape_cli;

Call verclientesordenalfabetico();

Create procedure verincidentesherido1()

Select*from incidentes where incicantheridos=1;

Call verincidentesherido1();

Visualizar los datos de los incidentes que han tenido un (1) herido, este reporte debe
visualizar la placa del automotor, con los respectivos datos de la póliza como son
fecha de inicio, valor, estado y valor asegurado.
Create procedure incidentedeunherido()

Select aseplaca, aseestado, asecosto, asevalorasegurado, asefechainicio, asefechaexpiracion from


incidentes, aseguramientos where incicantheridos = 1;

Call incidentedeunherido();

Create procedure incidentefll420()

Select incifecha, incilugar, incicantheridos, asefechainicio, asefechaexpiracion, asevalorasegurado


from aseguramientos where inciplaca = 'FLL420';

Call incidentefll420();

Create procedure detallepedido()

Select id_ped, tit_art, canart_artped, valven_artped from pedido

Inner join articuloxpedido on idped_artped = id_ped

Inner join articulo on id_art = idart_artped;

Call detallepedido();

Create procedure articuloxpedido()

Select*from , horascur, valorcur from Curso order by valorcur;

Call ordenamientovalor();
delimiter // CREATE FUNCTION mayores22() returns int(11)

begin

declare cantidad int;

select count(*) into cantidad from estudiante;

return cantidad;

end;

// delimiter;

Select mayores22();

Realice las Siguientes funciones en MySQL:


• Cuente el número de estudiantes cuya edad sea mayor a 22.
CREATE FUNCTION mayores22(INT) RETURNS INT(11) NOT DETERMINISTIC
CONTAINS SQL SQL SECURITY DEFINER BEGIN DECLARE cantidad int;
SELECT COUNT(*) INTO
cantidad FROM estudiante WHERE edad_est>'22'; RETURN cantidad; END
SELECT `contarestudiantes`(@p0) AS `contarestudiantes`

CREATE FUNCTION mayores22() RETURNS INT(11) NOT DETERMINISTIC CONTAINS SQL SQL
SECURITY DEFINER BEGIN DECLARE cantidad int;

SELECT COUNT(*) INTO cantidad FROM estudiante WHERE edad_est>'22'; RETURN cantidad; END;

delimiter //

CREATE FUNCTION contarestudiantes2() returns int

begin

declare cantidad int;

select count(*) into cantidad from estudiante where edadest>22;

return cantidad;

end

//
Calcule el valor promedio de los cursos cuyas horas sean mayores a 40.
delimiter //

CREATE FUNCTION promediocursosmay40() returns int

begin

declare promedio int;

select avg(valorcur) into promedio from curso where horascur > 40;

return promedio;

end

//

Select promediocursosmay40();

delimiter //

CREATE FUNCTION contarestudiantes2() returns int

begin

declare cantidad int;

select count(*) into cantidad from estudiante where edadest>22;

return cantidad;

end

//

delimiter //

CREATE FUNCTION estudiantecuba() returns varchar (255)

begin

declare datos varchar(255);

select concat_ws(' - ', nomest, edadest) into datos from estudiante where edadest = (select
min(edadest) from estudiante);

return datos;

end

//

Select estudiantecuba();
Obtener el sueldo promedio de los profesores de la categoría 1.
delimiter //

CREATE FUNCTION promedioprofescat1() returns int

begin

declare promedio int;

select avg(salprof) into promedio from profesor where cateprof = 1;

return promedio;

end

//

Select promedioprofescat1();

Muestre el nombre del profesor con menor sueldo.


delimiter //
CREATE FUNCTION profemenorsueldo() returns varchar (255)
begin
declare datos varchar(255);
select concat_ws(' - ', nomprof, salprof) into datos from profesor where salprof =
(select min(salprof) from profesor);
return datos;
end
//
Select profemenorsueldo();
Create table AudProfesor(auddoc_prof varchar(11) auto_increment, audnom_prof varchar(30),
audape_prof varchar(30), audcate_prof int, audsal_prof int, audmodificado datatime(6), primary
key(auddoc_prof)) auto_increment=1;

Create Table Audprofesor (


auddoc_prof varchar (11) not null,
audnom_prof varchar (30),
audape_prof varchar (30),
audcate_prof int,
audsal_prof int,
audmodificado datetime(6),
primary key (auddoc_prof)) ;
Create table curso (

Codcurs int auto_increment,

nomcurs varchar (100) not null,

horascur int not null,

valorcur int not null,

primary key (Codcurs)

);

Create Table Audcurso (


audcod_curs int (11) not null auto_increment,
audnom_curs varchar (100) not null,
audhoras_cur int(11) not null,
audvalor_cur int(11) not null,
audmodificado datetime(6),
primary key (audcod_curs)
) auto_increment=1;

Create table audestudiante (


auddoc_est varchar (11) not null,
audnom_est varchar (30) not null,
audape_est varchar (30) not null,
audedad_est int(11) not null,
audmodificado datetime(6),
primary key (auddoc_est)
);
create table Aseguramientos (
asecodigo int auto_increment,
asefechainicio date not null,
asefechaexpiracion date not null,
asevalorasegurado int not null,
aseestado varchar (30),
asecosto int not null,
aseplaca varchar (20),
primary key (asecodigo)
);

Create trigger nuevoprof after insert on profesor

for each row

insert into audprof(auddoc_prof, audnom_prof, audape_prof, audcate_prof, audsal_prof,


audmodificado)

values(docprof, nomprof, apeprof, cateprof, salprof, now());


auddoc_prof, audnom_prof, audape_prof, audcate_prof, audsal_prof, audmodificado)

Create trigger Modaudprofesor before update on profesor

For each row

Insert into audprofesor(antdocprof, antnomprof, antapeprof, antcateprof, antsalprof,


audmodificado) values (old.docprof, old.nomprof, old.apeprof, old.cateprof, old.salprof,
corrent_ser (), now());

Create trigger Eliaudprofesor after update on profesor

For each row

Insert into audprofesor(antdocprof, antnomprof, antapeprof, antcateprof, antsalprof,


audmodificado) values (old.docprof, old.nomprof, old.apeprof, old.cateprof, old.salprof,
corrent_ser (), now());

Create trigger nuevocurso after insert on curso

for each row

insert into audcurso(audcod_curs, audnom_curs, audhoras_cur, audvalor_cur, audmodificado)

values(codcurs, nomcurs, horascur, valorcur, now());


Create trigger Modaudcurso before update on curso

For each row

Insert into curso(antcodcurs, antnomcurs, anthorascur, antvalorcur,audmodificado) values


(oldcodcurs, old.nomcurs, old.horascur, old.valorcur, corrent_ser (), now());

Create trigger Eliaudcurso after update on curso

For each row

Insert into audcurso(antcodcurs, antnomcurs, anthorascur, antvalorcur,audmodificado)


values(oldcodcurs, old.nomcurs, old.horascur, old.valorcur, corrent_ser (), now());

Create trigger nuevoestudiante after insert on estudiante

for each row

insert into audestudiante(auddoc_est, audnom_est, audape_est, audedad_est, audmodificado)

values(docest, nomest, apeest, edadest, now());

Create trigger Modaudestudiante before update on estudiante

For each row

Insert into estudiante(antdocest, antnomest, antapeest, antedadest, audmodificado) values


(old.docest, old.nomest, old.apeest, old.edadest, corrent_ser (), now());

Create trigger Eliaudestudiante after update on estudiante

For each row

Insert into audestudiante(antdocest, antnomest, antapeest, antedadest, audmodificado)


values(old.docest, old.nomest, old.apeest, old.edadest, corrent_ser (), now());

Вам также может понравиться