Está en la página 1de 9

UNIVERSIDAD NACIONAL DE PIURA

Facultad de Ciencias Contables y


Financieras
AO DE LA DIVERSIFICACIN
PRODUCTIVA Y DEL FORTALECIMIENTO
DE LA EDUCACIN
TEMA

:
Trabajo Encargado.

CURSO

:
Anlisis de Sistemas II.

GRUPO

:
14

PROFESOR

:
Ing. Jorge Sandoval Rivera.

SEMESTRE

:
I - 2015

CICLO

:
IX

ALUMNA

o Cruz Ramrez, Evelyn Giuliana.

Fecha: Piura, 13 de Julio de 2015.

BASE DE DATOS FACTURACIN


create database facturacion
use facturacion
create table clientes
(idCliente int not null primary key,
nombre varchar(45)not null,
apellidos varchar(45) not null,
direccin varchar(45) not null,
telfono varchar(8) not null)

create table productos


(idProducto int not null primary key,
nombre_producto varchar(45)not null,
Precio_unitario money not null,
proveedor varchar(45) not null)

create table factura


(idFactura int not null primary key,
fecha_factura date not null,
idCliente int not null)

alter table factura add


constraint fk_factura_idCliente
foreign key (idCliente)
references clientes(idCliente)
ANLISIS DE SISTEMAS II

create table detalle_factura


(idDetalle_factura int not null primary key,
idFactura int not null,
idProducto int not null,
cantidad int not null)
alter table detalle_factura add
constraint fk_detalle_factura_idFactura
foreign key (idFactura)
references factura(idFactura)
alter table detalle_factura add
constraint fk_detalle_factura_idProducto
foreign key (idProducto)
references productos(idproducto)

insert into clientes (idCliente,nombre,apellidos,direccin,telfono)


values(1234532,'Evelyn','Cruz Ramirez', 'Silva Arevalo Mz.A19', '98984093')
insert into clientes values (3456778,'Edgardo','Lopez Vega','AA.HH EL
obrero','93456789')
insert into clientes values (8679056,'Harol','Quispe Cruz', 'Urb 21 de
Junio','93456723')
insert into clientes values (2378747, 'Cristian', 'Reyes Salcedo', 'Calle 9 de
octubre','93467892')
insert into clientes values (6578945,'Lourdes', 'Juarez Carreo', 'centro civico
N 23','98567482')
insert into productos (id Producto, nombre_producto,Precio_unitario,
proveedor)
values (011, 'monitor LCD', 400, 'DELL')
insert into productos values (013,'teclado',35,'GENIUS')
insert into productos values (012,'torre ATX',685,'IBM')
insert into productos values (010,'monitor LCD',694,'LG')
insert into productos values (014,'televisor',600,'Samsumg')

insert into factura (idFactura, fecha_factura, idCliente)


values (01,'09/05/2010',1234532)
insert into factura values (03,'12/05/2010',8679056)
insert into factura values (05,'15/05/2010',3456778)
insert into factura values (02,'10/05/2010',6578945)
insert into factura values (04,'12/05/2010',2378747)

insert into detalle_factura (idDetalle_factura,idFactura,idProducto,cantidad)


ANLISIS DE SISTEMAS II

values (1,01,010,2)
insert into detalle_factura
insert into detalle_factura
insert into detalle_factura
insert into detalle_factura

values
values
values
values

(2,02,011,1)
(3,03,012,2)
(4,04,013,1)
(5,05,014,2)

DIAGRAMA DE BASE DE DATOS FACTURACION

SUBCONSULTAS
ANLISIS DE SISTEMAS II

1) MOSTRAR Nombres y Apellidos DE LOS CLIENTES QUE COMPRARON


DOS PRODUCTOS
select nombre,apellidos from clientes
where idCliente in(select idCliente from factura
where idFactura in(select idFactura from detalle_factura where
cantidad = 2))

2) MOSTAR EL NOMBRE DEL PRODUCTO QUE SE FACTUR EL


12/05/2010
select nombre_producto from productos
where idProducto in(select idProducto from detalle_factura
where idDetalle_factura in(select idFactura from factura where
fecha_factura= '12/05/2010'))

3) MOSTRAR EL CDIGO DE FACTURA DE LOS CLIENTES CUYO


NOMBRE COMIENCE CON LA LETRA E
select idFactura from factura
where idCliente in(select idCliente from clientes where nombre
like 'E%')

ANLISIS DE SISTEMAS II

4) MOSTRAR EL NOMBRE DEL PRODUCTO QUE SE VENDIO AL CLIENTE


QUE TIENE CODIGO DE CLIENTE 1234532
select nombre_producto from productos
where idProducto in(select idProducto from detalle_factura
where idDetalle_factura in( select idFactura from factura where
idCliente=1234532))

5) MOSTRAR NOMBRE Y PRECIO DE PRODUCTO VENDIDO A UN PRECIO


MENOR A 500 SOLES Y CON FACTURA N 04

Select nombre_producto,Precio_unitario from productos


where idProducto in(select idProducto from detalle_factura
where idDetalle_factura in(select idFactura from factura
where( Precio_unitario <500) and (idFactura= 04)))

ANLISIS DE SISTEMAS II

COMBINACIONES
MOSTRAR LOS DATOS
DETALLE_FACTURA

DE

LA

TABLA

PRODUCTOS

select * from productos inner join detalle_factura on


productos.idProducto= detalle_factura.idProducto

MOSTRAR APELLIDOS, TELEFONO Y FECHA DE FACTURA


select c.apellidos, c.telfono, f.fecha_factura
from clientes as c inner join factura as f
on c.idCliente= f.idCliente

MOSTRAR NOMBRE DEL PRODUCTO IDFACTURA Y FECHA DE


FACTURA
Select P.nombre_producto, D.idFactura, F.fecha_factura
from productos as P inner join detalle_factura as D
on P.idProducto = D.idProducto inner join factura as F
on D.idFactura=F.idFactura

ANLISIS DE SISTEMAS II

MOSTRAR CDIGO DE PRODUCTO, CANTIDAD DE PRODUCTO,


CDIGO DE FACTURA Y FECHA DE FACTURA
select d.idProducto as 'codigo de producto',d.cantidad'cantidad
de producto',d.idfactura as 'codigo de factura',f.fecha_factura
as 'Fecha de Factura' from detalle_factura as d inner join
factura as f on d.idFactura=f.idFactura

COMBINACIN DE 4 TABLAS : Mostrar Nombre de cliente, fecha de


factura, cantidad de producto ,producto y proveedor
select C.nombre as 'Nombre de cliente', F.fecha_factura as
'Fecha de Factura', D.cantidad as 'cantidad de producto',
P.nombre_producto as 'Producto', P.proveedor
from clientes as C inner join factura as F
on C.idCliente= F.idCliente inner join detalle_factura as D
on F.idFactura= D.idFactura inner join productos as P
on D.idProducto= P.idProducto

ANLISIS DE SISTEMAS II

UPDATE
ACTUALIZAR EL NOMBRE DEL CLIENTE EVELYN POR SU
SEGUNDO NOMBRE GIULIANA
update clientes set nombre='Giuliana' where apellidos='Cruz
Ramirez'and nombre= 'Evelyn'

DELETE
LOS MONITORES LCD DE LA MARCA LG Y DELL SE AGOTARON
DELETE FROM productos Where nombre_producto='monitor
LCD' and proveedor='DELL' and nombre_producto='monitor
LCD' and proveedor='LG'

ANLISIS DE SISTEMAS II

También podría gustarte