-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMILICIA.sql
More file actions
92 lines (76 loc) · 2.08 KB
/
Copy pathMILICIA.sql
File metadata and controls
92 lines (76 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Create database Milicia;
use Milicia;
create table Cuerpo(
cod_cuerpo int,
denominacion varchar(200),
primary key(cod_cuerpo)
);
create table Compania(
num_compania int,
actividad varchar(50),
primary key(num_compania)
);
create table Cuartel(
cod_cuartel int ,
nom_cuartel varchar(50),
ubicacion varchar(50),
primary key(cod_cuartel)
);
create table Soldado(
cod_soldado int not null,
nombre varchar(100),
apellido Varchar(100),
graduacion varchar(50),
cuerpo int,
compania int,
cuartel int,
primary key (cod_soldado),
constraint c1 foreign key (cuerpo) references Cuerpo(cod_cuerpo),
constraint c2 foreign key (compania) references Compania(num_compania),
constraint c3 foreign key (cuartel) references Cuartel(cod_cuartel)
);
create table Servicio(
cod_servicio int,
fecha date,
descripcion varchar(150),
primary key(cod_servicio)
);
create table Detalle_Servicio(
id int auto_increment not null,
codServicio int,
codSoldado int,
primary key(id),
constraint c4 foreign key (codServicio) references Servicio(cod_servicio),
constraint c5 foreign key (codSoldado) references Soldado(cod_soldado)
);
#1
select Soldado.cod_soldado, Cuerpo.denominacion from Soldado,Cuerpo where Soldado.cod_soldado = Cuerpo.cod_cuerpo order by Cuerpo.cod_cuerpo asc ;
#2
#3
select * from Servicio;
#4
select cod_soldado,nombre, actividad from Soldado,Compania where Soldado.compania = Compania.num_compania;
#5
select cod_soldado,nombre, nom_cuartel,ubicacion from Soldado,Cuartel where Soldado.cuartel = Cuartel.cod_cuartel;
DELIMITER $
create procedure `consultas`(a int)
begin
case a
when 1 then
#1
select Soldado.cod_soldado, Cuerpo.denominacion from Soldado,Cuerpo where Soldado.cod_soldado = Cuerpo.cod_cuerpo order by Cuerpo.cod_cuerpo asc ;
when 2 then
#2
select*;
when 3 then
#3
select * from Servicio;
when 4 then
#4
select cod_soldado,nombre, actividad from Soldado,Compania where Soldado.compania = Compania.num_compania;
when 5 then
#5
select cod_soldado,nombre, nom_cuartel,ubicacion from Soldado,Cuartel where Soldado.cuartel = Cuartel.cod_cuartel;
end case;
end$
CALL Milicia.consultas(3);