Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Profesor
create procedure regprofesor2(doc_prof varchar(11), nom_prof varchar(30), ape_prof
varchar(30), cate_prof int(11), sal_prof int(11))
insert into profesores
(doc_prof,nom_prof,ape_prof,cate_prof,sal_prof)
values(doc_prof,nom_prof,ape_prof,cate_prof,sal_prof);
call regprofesor2('9100400','Paula','Herrera',2,1500000)
Cursos
create procedure regcursos(nom_curs varchar(100), horas_cur int(11), valor_cur
int(11))
insert into cursos
(nom_curs,horas_cur,valor_cur)
values(nom_curs,horas_cur,valor_cur);
Estudiante
create procedure regestudiantes(doc_est varchar(11),nom_est varchar(30),ape_est
varchar(30),edad_est int(11))
insert into estudiantes
(doc_est,nom_est,ape_est,edad_est)
values(doc_est,nom_est,ape_est,edad_est);
Estudiantexcurso
create procedure regestxcurso(cod_cur_estcur int(11),doc_est_estcur
int(30),fec_ini_estcur date)
insert into estudiantexcurso
(cod_cur_estcur,doc_est_estcur,fec_ini_estcur)
values(cod_cur_estcur,doc_est_estcur,fec_ini_estcur);
+---+---+---+---+---+---+
___________________________________________________________________________________
__
• En SQL SERVER; para las tablas Compañía, TipoAutomotores, Automotores,
Aseguramientos, Incidentes.
AS
GO
AS
SET NOCOUNT ON;
INSERT INTO automotores
(autoplaca, automarca, autotipo,
automodelo,autopasajeros,autocilindraje,autonumchasis)
VALUES(@autoplaca,@automarca,@autotipo,@automodelo,
@autopasajeros,@autocilindraje,@autonumchasis)
GO
@nom varchar(30)
AS
SET NOCOUNT ON;
INSERT INTO tiposautomotores
(nom)
VALUES (@nom)
GO
AS
SET NOCOUNT ON;
INSERT INTO aseguramientos
(asecodigo, asefechainicio, asefechaexpiracion,
asevalorasegurado,aseestado,asecosto,aseplaca)
VALUES(@asecodigo,@asefechainicio,@asefechaexpiracion,@asevalorasegurado,
@aseestado,@asecosto,@aseplaca)
GO
AS
SET NOCOUNT ON;
INSERT INTO incidentes
(incicodigo, incifecha, inciplaca,
incilugar,inciantheridos,incicanfatalidades,incicanautosinvolucrados)
VALUES(@incicodigo, @incifecha, @inciplaca,
@incilugar ,@inciantheridos ,@incicanfatalidades,@incicanautosinvolucrados)
GO
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
AS
BEGIN
SELECT * FROM AUTOMOTORES, aseguramientos
WHERE
autoplaca = aseplaca
and asefechaexpiracion >= '2013-01-01';
SET NOCOUNT ON;
END
GO
AS
BEGIN
SELECT * FROM AUTOMOTORES, incidentes
WHERE
autoplaca = inciplaca
and inciantheridos = 1;
SET NOCOUNT ON;
END
AS
BEGIN
Select inciplaca, incifecha, incilugar, inciantheridos, asefechainicio,
asefechaexpiracion, asevalorasegurado
From incidentes, aseguramientos
Where inciplaca=aseplaca
and inciplaca = 'FLL420';
SET NOCOUNT ON;
END
GO
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
mysql> delimiter //
mysql> create function contar3() returns int
-> begin
-> declare cantidad int;
-> select count(doc_est) into cantidad from estudiantes
-> where edad_est >22;
-> return cantidad;
-> end
-> //
mysql> delimiter //
mysql> create function estudiantemasjoven() returns varchar(30)
-> begin
-> declare nombre varchar(30);
-> declare edad varchar(9);
-> select nom_est , edad_est into nombre , edad from estudiantes
-> where edad_est = (select min(edad_est) from estudiantes);
-> return concat (nombre , " " , edad);
-> end
-> //
mysql> delimiter //
mysql> create function promediocurso() returns int
-> begin
-> declare promedio decimal (11,2);
-> select avg(valor_cur) into promedio from cursos
-> where horas_cur > 40;
-> return promedio;
-> end
-> //
mysql> delimiter //
mysql> create function sueldopromedioprof() returns int
-> begin
-> declare sueldprom decimal(11,2);
-> select avg(sal_prof) into sueldprom from profesores
-> where cate_prof = 1;
-> return sueldoprom;
-> end
-> //
mysql> delimiter //
mysql> create function profmenorsueldo() returns int
-> begin
-> declare nombre varchar(30);
-> declare sueldo int;
-> select nom_prof , sal_prof into nombre , sueldo from profesores
-> where sal_prof = (select min(sal_prof) from profesores);
-> return concat (nombre " " sueldo);
-> end
-> //
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Name
-- Create date:
-- Description:
-- =============================================
alter FUNCTION polizacostosa
(
)
RETURNS TABLE
AS
RETURN
(
select * from aseguramientos
where asecosto= (select max(asecosto) from aseguramientos)
-- Add the SELECT statement with parameter references here
)
GO
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
+---+---+
--Cursos
mysql> create table aud_cursos(
-> id_aud_cursos int not null auto_increment primary key,
-> Ant_nom_curs varchar(100) not null,
-> Ant_horas_cur int(11) not null,
-> Ant_valor_cur int(11) not null,
-> new_nom_curs varchar(100) not null,
-> new_horas_cur int(11) not null,
-> new_valor_cur int(11) not null,
-> cod_curs int(11) not null,
-> usuario_curs varchar(30) not null,
-> fecha_cur datetime not null,
-> accion_cur varchar(30) not null
-> ) auto_increment=1;
mysql> delimiter //
mysql> create trigger trg_cursos_update
-> before update on cursos
-> for each row
-> begin
-> insert into aud_cursos(
-> Ant_nom_curs , Ant_horas_cur, Ant_valor_cur, new_nom_curs, new_horas_cur,
new_valor_cur, cod_curs, usuario_curs, fecha_cur, accion_cur)
-> values(old.nom_curs , old.horas_cur , old.valor_cur , new.nom_curs,
new.horas_cur , new.valor_cur, new.cod_curs , current_user() , now() ,
'Actualización');
-> end;
-> //
mysql> delimiter //
mysql> create trigger trg_cursos_delete
-> after delete on cursos
-> for each row
-> begin
-> insert into aud_cursos(
-> Ant_nom_curs , Ant_horas_cur, Ant_valor_cur,cod_curs, usuario_curs,
fecha_cur, accion_cur)
-> values(old.nom_curs , old.horas_cur , old.valor_cur , current_user() , now()
, 'Borrado');
-> end;
--Esudiantes
mysql> create table audi_estudiantes(
-> aud_id_est int not null auto_increment primary key,
-> aud_nom_est_ant varchar(30) not null,
-> aud_ape_est_ant varchar(30) not null,
-> aud_edad_est_ant int(11) not null,
-> aud_nom_est_new varchar(30) not null,
-> aud_ape_est_new varchar(30) not null,
-> aud_edad_est_new int(11) not null,
-> usuario varchar(30) not null,
-> doc_est varchar(11) not null,
-> aud_fec_est datetime not null,
-> aud_accion varchar(20) not null
-> );
Query OK, 0 rows affected (0.01 sec)
mysql> delimiter //
mysql> create trigger trg_estudiantes_update
-> before update on estudiantes
-> for each row
-> begin
-> insert into audi_estudiantes(
-> aud_nom_est_ant , aud_ape_est_ant , aud_edad_est_ant , aud_nom_est_new ,
aud_ape_est_new , aud_edad_est_new , usuario, doc_est, aud_fec_est, aud_accion)
-> values(old.nom_est , old.ape_est , old.edad_est , new.nom_est,
new.edad_est , new.edad_est , current_user() , new.doc_est , now(), 'Update')
-> ;
-> end;
-> delimiter ;
-> //
mysql> delimiter //
mysql> create trigger trg_estudiantes_delete
-> after delete on estudiantes
-> for each row
-> begin
-> insert into audi_estudiantes(
-> aud_nom_est_ant , aud_ape_est_ant , aud_edad_est_ant , usuario , doc_est ,
aud_fec_est , aud_accion)
-> values(old.nom_est , old.ape_est , old.edad_est , current_user() , doc_est ,
now(), 'Delete')
-> ;
-> end;
-> delimiter
-> //
---CLIENTES
create trigger trg_clientes
before update on clientes
for each row
begin
insert into aud_clientes(
AUD_NOM_CLI_ANT , AUD_APE_CLI_ANT , AUD_DIR_CLI_ANT , AUD_DEP_CLI_ANT ,
MES_CUM_CLI_ant ,
AUD_NOM_CLI_NEW , AUD_APE_CLI_NEW , AUD_DIR_CLI_NEW,
AUD_DEP_CLI_NEW,MES_CUM_CLI_NEW,USUARIO,FEC_MOD,ACCION , AUD_ID_CLI_ANT ,
AUD_ID_CLI_NEW)
values
(:old.NOM_CLI, :old.APE_CLI, :old.DIR_CLI, :old.DEP_CLI, :old.MES_CUM_CLI, :new.NOM
_CLI,
:new.APE_CLI, :new.DIR_CLI, :new.DEP_CLI, :new.MES_CUM_CLI, user, SYSDATE,
'Actualización' ,
:OLD.ID_CLI , :NEW.ID_CLI);
end;
END;
---TABLA ARTICULOS
create trigger trg_ARTICULOS_UPDATE
before update on ARTICULOS
for each row
begin
insert into aud_articulos(
AUDTITART_AN , AUDAUTART_AN , AUDEDIART_AN , AUDPRECART_AN , AUDTITART_NU ,
AUDAUTART_NU , AUDEDIART_NU , AUDPRECART_NU , ACCION , FECHAMOD , USUARIO , ID_ART)