Está en la página 1de 21

SERVICIO NACIONAL DE ADIESTRAMIENTO EN TRABAJO INDUSTRIAL

PLAN DE TRABAJO
DEL ESTUDIANTE
TRABAJO FINAL DEL CURSO

1. INFORMACIÓN GENERAL

Apellidos y Nombres: Campos Lupe Jorge Luis ID: 1262801


Dirección Zonal/CFP: Zonal Callao
Carrera: Administración de base de datos Semestre: II
Curso/ Mód. Formativo Desarrollo de base de datos con MySQL
Tema del Trabajo: Base de datos de empresa de abarrotes

2. PLANIFICACIÓN DEL TRABAJO


N
ACTIVIDADES/ ENTREGABLES CRONOGRAMA/ FECHA DE ENTREGA
°
Entregable TR1 29/11
Entregable TR2

3. PREGUNTAS GUIA
Durante la investigación de estudio, debes obtener las respuestas a las siguientes interrogantes:

N.º PREGUNTAS

1 ¿Qué metodologías existen para diseñar una base de datos?

2 ¿En qué consiste en diseño físico y lógico de una base de datos?

3 ¿Qué es un modelo de Entidad Relación? Detallar sus componentes

¿Qué son entidades, relaciones, atributos, identificadores y jerarquías dentro de una base de
4
datos?

5 ¿Cuáles con las principales sentencias del lenguaje SQL y para qué sirven?

2
TRABAJO FINAL DEL CURSO

HOJA DE RESPUESTAS A LAS PREGUNTAS GUÍA

1.

Existe el Modelo Conceptual, Lógico y Físico, también el modelado orientado a objetos.

2.

El Diseño lógico es la conversión del esquema conceptual, que tiene como objetivo obtener una
representación que use de la manera más eficiente posible los recursos para la estructuración de
datos.

El diseño físico forma parte del proceso general de diseño de una base de datos. En particular, se
realiza después del diseño lógico de la misma. En este se genera un conjunto de tablas normalizadas.
3.

Es una herramienta para el modelo de datos, la cual facilita la representación de entidades de una
base de datos. Sus componentes son las entidades y relaciones.

4.

Entidad: unidad que contiene información


Relación: es la forma en que se unen 2 o más entidades.
Atributo: es la descripción de la entidad.
Identificador: nombre de un objeto de la base de datos.

5.

SELECT: se utiliza para consultar datos.


DISTINCT: sirve para eliminar los duplicados de las consultas de datos.
WHERE: se utiliza incluir las condiciones de los datos que queremos consultar.
AND y OR: se utilizan para incluir 2 o más condiciones a una consulta.
ORDER BY: se utiliza para ordenar los resultados de una consulta.
INSERT: se utiliza para insertar datos.
UPDATE: se utiliza actualizar o modificar datos ya existentes.
DELETE: se utiliza borrar datos.

3
TRABAJO FINAL DEL CURSO

HOJA DE PLANIFICACIÓN

PROCESO DE EJECUCIÓN
SEGURIDAD / MEDIO AMBIENTE /
OPERACIONES / PASOS /SUBPASOS NORMAS -ESTANDARES
Estudio del caso Ambiente iluminado correctamente
Análisis del requerimiento Silla ergonómica
Identificación de las reglas de negocio Escritorio
Identificación de entidades Ambiente con temperatura adecuada
Identificación de relaciones Tomas eléctricas en buen estado
Creación del modelo conceptual
Identificación de cardinalidades
Creación del modelo lógico
Creación del modelo físico
Implementación de la base de datos

INSTRUCCIONES: Debes ser lo más explícito posible. Los gráficos ayudan a transmitir
mejor las ideas. No olvides los aspectos de calidad, medio ambiente y SHI.

4
TRABAJO FINAL DEL CURSO

DIBUJO / ESQUEMA/ DIAGRAMA

Diagrama de base de datos

5
TRABAJO FINAL DEL CURSO

Campos Lupe Jorge [ESCALA]

Diagrama de base de datos

6
TRABAJO FINAL DEL CURSO

Campos Lupe Jorge [ESCALA]

7
TRABAJO FINAL DEL CURSO

Diagrama de base de datos

Campos Lupe Jorge [ESCALA]

8
TRABAJO FINAL DEL CURSO

Diagrama de base de datos

Campos Lupe Jorge [ESCALA]

9
TRABAJO FINAL DEL CURSO

drop database if exists abarrotes;


create database abarrotes;
use abarrotes;

drop table if exists Cliente;


create table Cliente(
Cod char(5) not null primary key,
Nombre varchar(50) not null,
Apellido varchar(50) not null,
FechNac date not null,
Telf int null,
Dni char(8) not null unique,
Email varchar(50) not null
);
alter table Cliente add FechNac date not null after Apellido;
alter table Cliente modify FechNac timestamp not null;
alter table Cliente drop column FechNac;
drop procedure if exists sp_InsertarCliente;
delimiter $$
create procedure sp_InsertarCliente( in _cod char(5),nom varchar(50), ape
varchar(50), tlf int, dni char(8),email varchar(50),OUT msj varchar(40))
begin
if _cod is null or _cod = "" then
set msj='ingrese codigo';

elseif nom is null or nom = "" then


set msj ='ingrese nombre';

elseif ape is null or ape = "" then


set msj = 'ingrese apellido';

elseif tlf is null or tlf = "" then


set msj = 'ingrese telefono';

elseif dni is null or dni = "" then


set msj = 'ingrese dni';

elseif email is null or email = "" then


set msj = 'ingrese email';

else
insert Cliente(Cod, Nombre, Apellido,Telf, Dni, Email)
value (_cod,nom,ape,tlf,dni,email);
set msj = 'registrado con exito';
end if;
end $$
delimiter ;
insert Cliente values ('C0001','b','c',"1993-10-
10",'95421453','23642764','arodriguez@hotmail.com');
10
TRABAJO FINAL DEL CURSO

call sp_InsertarCliente
("C0002","b","sssc","95421453","11111111","arodriguez@hotmail.com",@m
sj);
select @msj;
select * from Cliente;

delimiter $$
create procedure sp_ActualizarCliente(in _cod char(5), nom varchar(50), ape
varchar(50), fnac date, tlf int, dni char(8), email varchar(50),OUT msj
varchar(40))
begin
update Cliente set Nombre = nom, Apellido = ape, FechNac = fnac,Telf
= tlf, Email = email WHERE Cod = _cod;
set msj = "Se actualizo cliente";
end $$
delimiter ;

call sp_ActualizarCliente('C0001','zzzzzz','xxxx','1993-10-
10',95421453,"12345678",'mrodriguez@hotmail.com',@msj);
select @msj;

delimiter $$
create procedure sp_BuscarCliente(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
select * from Cliente
where Cod = _cod;
end if;
end $$
delimiter ;

call sp_BuscarCliente("C0001",@msj)

delimiter $$
create procedure sp_EliminarCliente(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
delete from cliente
where Cod = _cod;
end if;
end $$
delimiter $$

drop table if exists Usuario;


create table Usuario(
Id char(5) not null primary key,
nombre varchar(30) not null unique,
11
TRABAJO FINAL DEL CURSO

contraseña varchar(40) not null,


estado int not null,
CodCli char(5) not null,
foreign key(CodCli) references Cliente(Cod)
);

drop table if exists Proveedor;


create table Proveedor(
Cod char(5) not null primary key,
RazonSocial varchar(50) not null,
Telefono int not null
);

drop table if exists Producto;


create table Producto(
Cod char(5) not null primary key,
Nombre varchar(40) not null,
Tipo varchar(40) not null,
Precio decimal(8,2) not null
);

drop table if exists Empleado;


create table Empleado(
Cod char(5) not null primary key,
Nombre varchar(40) not null,
Apellido varchar(50) not null,
FechaNa date not null,
Telefono int not null,
FechaContra date not null,
Cargo varchar(30) not null,
Dni char(8) not null unique
);

drop table if exists Compra;


create table Compra(
Cod char(5) not null primary key,
FechaCompra date not null,
FechaEnvio date not null,
CodEmp char(5) not null,
IdUsu char(5) not null,
foreign key(CodEmp) references Empleado(Cod),
foreign key(IdUsu) references Usuario(Id)
);

drop table if exists Comprobante;


create table Comprobante(
Cod char(5) not null primary key,
Fecha date not null,
Tipo varchar(20) not null,
Subtotal decimal(8,2),
Igv decimal(8,2),
12
TRABAJO FINAL DEL CURSO

Total_Pago decimal(8,2),
CodCompra char(5) not null,
foreign key(CodCompra) references Compra(Cod)
);

drop table if exists ComprasProducto;


create table ComprasProducto(
CodCompra char(5) not null,
CodProd char(5) not null,
Cantidad int not null,
Total decimal(8,2) not null,
foreign key(CodCompra) references Compra(Cod),
foreign key(CodProd) references Producto(Cod)
);

drop table if exists ProveedorProducto;


create table ProveedorProducto(
CodProd char(5) not null,
CodProv char(5) not null,
foreign key(CodProd) references Producto(Cod),
foreign key(CodProv) references Proveedor(Cod)
);

drop table if exists Inventario;


create table Inventario(
Num int not null primary key,
CodPro char(5) not null,
Fecha date not null,
TotalEntrada int not null,
TotalSalida int not null,
Stock int not null,
foreign key(CodPro) references Producto(Cod)
);

drop table if exists Entrada;


create table Entrada(
Num int not null primary key,
Fecha date not null,
Cantidad int not null,
CodPro char(5) not null,
foreign key(CodPro) references Producto(Cod)
);

drop table if exists Salida;


create table Salida(
Num int not null primary key,
Fecha date not null,
Cantidad int not null,
Observacion varchar(100),
CodPro char(5) not null,
foreign key(CodPro) references Producto(Cod)
13
TRABAJO FINAL DEL CURSO

);

delimiter $$
create procedure sp_InsertarUsuario( in _id char(5),nom varchar(30), ctr
varchar(40), estado int, _cod char(5),OUT msj varchar(40))
begin
if _id is null or _id = "" then
set msj='ingrese codigo';

elseif nom is null or nom = "" then


set msj ='ingrese nombre';

elseif ctr is null or ctr = "" then


set msj = 'ingrese contraseña';

elseif estado is null or estado = "" then


set msj = 'igrese estado';

elseif _cod is null or _cod = "" then


set msj = 'ingrese codigo';
else
insert Usuario (Id, nombre , contraseña , estado , CodCli ) values
(_id,nom,ctr,estado,_cod);
set msj = 'registrado con exito';
end if;
end; $$
delimiter ;

call sp_InsertarUsuario('U0001','arodrig','1234',1,'C0001',@msj);
select @msj;
select * from Usuario;
delete from usuario
where Id = 'C0002';
delimiter $$
create procedure sp_ActualizarUsuario( in _id char(5),nom varchar(30), ctr
varchar(40), estado int, cod char(5),OUT msj varchar(40))
begin
update usuario set nombre = nom, contraseña = ctr, estado = estado,
CodCli = cod
where Id = _id;
set msj = "Se actualizo usuario";
end $$
delimiter ;

delimiter $$
create procedure sp_BuscarUsuario(in _id char(5), out msj varchar(50))
begin
if _id = "" then
set msj = "ingrese id";
else
14
TRABAJO FINAL DEL CURSO

select * from Usuario


where Id = _id;
end if;
end $$
delimiter ;

call sp_BuscarUsuario("U0001",@msj)

delimiter $$
create procedure sp_EliminarUsuario(in _id char(5), out msj varchar(50))
begin
if _id = "" then
set msj = "ingrese id";
else
delete from Usuario
where Id = _id;
end if;
end $$
delimiter $$

delimiter $$
create procedure sp_InsertarProveedor( in _cod char(5), rz varchar(50) , tlf
int, OUT msj varchar(40))
begin
if _cod is null or _cod then
set msj='ingrese codigo';

elseif rz is null or rz = "" then


set msj ='ingrese razon social';

elseif tlf is null or tlf = "" then


set msj = 'ingrese telefono';
else
insert Proveedor (Cod , RazonSocial , Telefono ) values (_cod,rz,tlf);
set msj = 'registrado con exito';
end if;
end; $$
delimiter ;

call sp_InsertarProveedor('P0001','saga',324243,@msj);
select @msj;
select * from Proveedor;

delimiter $$
create procedure sp_ActualizarProveedor( in _cod char(5), rz varchar(50) , tlf
int, OUT msj varchar(40))
begin
update Proveedor set RazonSocial = rz, Telefono = tlf
where Cod = _cod;
set msj = "Se actualizo proveedor";
end $$
15
TRABAJO FINAL DEL CURSO

delimiter ;

call sp_ActualizarProveedor('P0002','vea',423252,@msj);
select @msj;

delimiter $$
create procedure sp_BuscarProveedor(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
select * from Proveedor
where Cod = _cod;
end if;
end $$
delimiter ;

delimiter $$
create procedure sp_EliminarProveedor(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
delete from Usuario
where Cod = _cod;
end if;
end $$
delimiter $$

-- *******************************************************************************--

delimiter $$
create procedure sp_InsertarProducto( in _cod char(5), nom varchar(50) , tip
varchar(40),prec decimal, OUT msj varchar(40))
begin
if _cod is null or _cod = ""then
set msj='ingrese codigo';

elseif nom is null or nom = "" then


set msj ='ingrese nombre';

elseif tip is null or tip = "" then


set msj = 'ingrese tipo';

elseif prec is null or prec = "" then


set msj = 'ingrese precio';
else
insert Producto (Cod , Nombre , Tipo ,Precio ) values (_cod,nom,tip,
prec);
16
TRABAJO FINAL DEL CURSO

set msj = 'registrado con exito';


end if;
end; $$
delimiter ;

call sp_InsertarProducto('PR002','arroz','semillas',13,@msj);
select @msj;
select * from Producto;

delimiter $$
create procedure sp_ActualizarProducto(in _cod char(5), nom varchar(50) ,
tip varchar(40),prec decimal, OUT msj varchar(40))
begin
update Producto set Nombre = nom, Tipo = tip, Precio =prec
where Cod = _cod;
set msj = "Se actualizo producto";
end $$
delimiter ;

call sp_ActualizarProducto('PR002','cocinero','aceite',11,@msj);
select @msj;

delimiter $$
create procedure sp_BuscarProducto(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
select * from Producto
where Cod = _cod;
end if;
end $$
delimiter ;

delimiter $$
create procedure sp_EliminarProducto(in _cod char(5), out msj varchar(50))
begin
if _cod = "" then
set msj = "ingrese codigo";
else
delete from Producto
where Cod = _cod;
end if;
end $$
delimiter ;
SET SQL_SAFE_UPDATES = 0;
alter table comprasproducto add PrUni int not null after Cantidad;
UPDATE comprasproducto SET Total = (PrUni * Cantidad);
select * from compra;
select * from comprasproducto;
17
TRABAJO FINAL DEL CURSO

insert empleado values('E0002','Ana','Perez','1992-10-10',9522146,'2005-10-


10','cajero','12345862');
insert compra values('CO001','2019-05-11','2019-05-13','E0002','U0001');
insert comprasproducto values('CO001','PR002',3,33,11);
-- ********************************************************************************* --
delimiter $$
create function ObtenerTotal(nped int)
returns decimal(10,2)
READS SQL DATA
DETERMINISTIC
begin
declare ntotal decimal(10,2);
set ntotal = (select sum(Total) from comprasproducto
where CodCompra = nped);
return ntotal;
end $$
delimiter ;
select * from comprasproducto;
select ObtenerTotal(10249);

delimiter $$
drop function if exists ObtenerSubTotal;
Create function ObtenerSubTotal(Pedido int)
returns decimal(10,2)
Reads Sql Data
Deterministic
Begin
Declare Subtotal decimal(10,2);
Set Subtotal = (ObtenerTotal(Pedido) /1.18);
Return Subtotal;
End $$
delimiter ;

Select ObtenerSubTotal(10248);

delimiter $$
drop function if exists ObtenerIgv;
Create function ObtenerIgv(nro_pedido int)
returns decimal(10,2)
Reads Sql Data
Deterministic
Begin
Declare igv decimal(10,2);
Set igv = (ObtenerTotal(nro_pedido) - ObtenerSubtotal(nro_pedido));
Return igv;
End $$
delimiter ;

alter table comprobante modify column Cod INT AUTO_INCREMENT;


select * from comprobante;
delimiter $$
18
TRABAJO FINAL DEL CURSO

create procedure sp_generarcomprobante(in tip varchar(20), nro_ped int)


begin
if tip = 'factura' then
insert comprobante(Fecha, Tipo, SubTotal, Igv, Total_pago,
CodCompra)
values (CURTIME(), 'Factura', ObtenerSubTotal(nro_ped),
ObtenerTotal(nro_ped), ObtenerIgv(nro_ped));
else
insert comprobante(Fecha,Tipo, Total_Pago, CodCompra)
values(CURTIME(),'Boleta',ObtenerTotal(nro_ped),nro_ped);
end if;
end $$
delimiter ;

call sp_generarcomprobante('factura', 10249);

delimiter $$
create procedure sp_InsertarInventario( in _num int, cod char(5) , fecha
date,tentrada int,tsalida int, stock int, OUT msj varchar(40))
begin
if _num is null or _num = ""then
set msj='ingrese numero';

elseif cod is null or cod = "" then


set msj ='ingrese codigo';

elseif fecha is null or fecha = "" then


set msj = 'ingrese fecha';

elseif tentrada is null or tentrada = "" then


set msj = 'ingrese total entrada';

elseif tsalida is null or tsalida = "" then


set msj = 'ingrese total salida';

elseif stock is null or stock = "" then


set msj = 'ingrese stock';

else
insert Producto (Num , CodPro, Fecha ,TotalEntrada, TotalSalida,
Stock ) values (_num,cod,fecha, tentrada, tsalida,stock );
set msj = 'registrado con exito';
end if;
end; $$
delimiter ;

call sp_InsertarInventario(1,'PR002','2020-10-10', '20','15',5,@msj);

delimiter $$
create procedure sp_ActualizarInventario( in _num int, cod char(5) , fecha
date,tentrada int,tsalida int, stock int, OUT msj varchar(40))
19
TRABAJO FINAL DEL CURSO

begin
update Inventario set CodPro = cod, Fecha =fecha,
TotalEntrada=tentrada, TotalSalida = tsalida, Stock = stock
where Num = _num;
set msj = "Se actualizo inventario";
end $$
delimiter ;

call sp_ActualizarProducto('PR002','cocinero','aceite',11,@msj);
select @msj;

delimiter $$
create procedure sp_BuscarInventario(in _num int, out msj varchar(50))
begin
if _num = "" then
set msj = "ingrese codigo";
else
select * from Inventario
where Num = _num;
end if;
end $$
delimiter ;

delimiter $$
create procedure sp_EliminarInventario(in _num int, out msj varchar(50))
begin
if _num = "" then
set msj = "ingrese codigo";
else
delete from Inventario
where Num = _num;
end if;
end $$
delimiter ;

LISTA DE RECURSOS
20
TRABAJO FINAL DEL CURSO

INSTRUCCIONES: completa la lista de recursos necesarios para la ejecución del trabajo.

1. MÁQUINAS Y EQUIPOS
1- Laptop
2- Mouse
3- Software

3. HERRAMIENTAS E INSTRUMENTOS

5. MATERIALES E INSUMOS

21

También podría gustarte