Está en la página 1de 9

/*Creación de una base de datos para una tienda de abarrotes*/

/* Creamos la base de datos y la usamos */


create database TIENDA
use TIENDA

/*creamos la tabla clientes y definimos los campos -- (contienes los datos del
cliente)*/
Create Table TBLCLIENTES
(
IdCliente int not null,
NomCliente varchar (50) not null,
NumDocumento bigint check (len (NumDocumento) >= 6 and len (NumDocumento)<10) not
null ,
Direccion varchar(50) not null,
Telefono varchar (30) check (len(Telefono) >= 7 and len (Telefono)<=10) default
null,
Email varchar (50),
Primary Key (IdCliente)
);

/*creamos la tabla empleados y definimos los campos -- (contienes los datos del
empleado)*/
Create Table TBLVENDEDOR
(
IdVendedor int not null,
NomVendedor varchar (50) not null,
NumDocumento bigint check (len (NumDocumento) >= 6 and len (NumDocumento)<10) not
null,
Direccion varchar(50) not null,
Telefono varchar (30) check (len(Telefono) >= 7 and len (Telefono)<=10) not null,
Email varchar (50),
Primary Key (IdVendedor)
);

/*creamos la tabla proveedor y definimos los campos -- (contienes los datos del
proveedor)*/
Create Table TBLPROVEEDOR
(
IdProveedor int not null,
NomProveedor varchar (50) not null,
NumDocumento bigint check (len (NumDocumento) > 6 and len (NumDocumento)<10) not
null,
Direccion varchar(50) not null,
Telefono varchar (30) check (len(Telefono) >= 7 and len (Telefono)<=10) not null,
Email varchar (50)
Primary Key (IdProveedor)
);

/* creamos la tabla forma de pago y definimos los campos -- (define la forma de pago
(efectivo - devito - credito))*/
Create Table TBLPAGO
(
IdPago int not null,
NomFormaPago varchar (8) check (NomFormaPago ='Efectivo' or NomFormaPago ='Devito'
or NomFormaPago ='Credito') not null,
Primary Key (IdPago)
);

/* creamos la tabla Categorias y definimos los campos -- (define la categoria de


producctos(Granos - aseo - golosinas))*/
Create Table TBLCATEGORIA
(
IdCategoria int not null,
NomCategoria varchar(50) not null,
Primary Key (IdCategoria)
);

/* creamos la tabla productos y definimos los campos -- (contienes los datos del
producto)*/
Create Table TBLPRODUCTO
(
IdProducto int not null,
NomProducto varchar (50) not null,
Referencia varchar(20),
NumPrecioVenta decimal check (NumPrecioVenta >=50) not null,
IdCategoria int not null,
Detalle varchar(250),
NumStock int checK (NumStock > 0) not null,
Primary Key (IdProducto),
Foreign Key (IdCategoria) references TBLCATEGORIA (IdCategoria)
);

/*creamos la tabla compra y definimos los campos -- (contienes la relacion de los


productos comprados al proveedor)*/
Create Table TBLCOMPRA
(
IdCompra int not null,
NumFactura varchar (20) not null,
FechaCompra datetime not null,
PrecioCompra decimal not null,
IdProveedor int not null,
IdProducto int not null,
Cantidad int check (cantidad >0) not null,
Primary Key (IdCompra),
Foreign Key (IdProveedor) references TBLPROVEEDOR (IdProveedor),
Foreign Key (IdProducto) references TBLPRODUCTO (IdProducto)
);

/* creamos la tabla cajas y definimos los campos -- (contienes el numero de la caja


rejistradora)*/
Create Table TBLCAJA
(
IdCaja int not null,
NomCaja varchar (20) not null,
Primary Key (Idcaja)
);
/* creamos la tabla facturas y definimos los campos -- (contienes los datos
generales de la factuara)*/
Create Table TBLFACTURA
(
IdFactura int not null,
DtmFecha datetime not null,
IdCliente int not null,
IdVendedor int not null,
IdCaja int not null,
Primary Key (idFactura),
foreign Key (IdCliente) references TBLCLIENTES (IdCliente),
foreign Key (IdVendedor) references TBLVENDEDOR (IdVendedor),
foreign Key (IdCaja) references TBLCAJA (IdCAJA),
);

/* creamos la tabla detalles factura y definimos los campos -- (contienes el precio


unitario de los item de la factura)*/
Create Table TBLDETALLEFACTURA
(
IdDetalle int not null,
IdFactura int not null,
IdProducto int not null,
NumCantidad int check (NumCantidad >0) not null,
NumPrecio decimal check (NumPrecio >50)not null,
IdPago int not null,
Primary Key (IdDetalle),
Foreign Key (IdFactura) references TBLFACTURA (Idfactura),
Foreign Key (IdPRODUCTO) references TBLPRODUCTO (IdProducto),
Foreign Key (IdPago) references TBLPAGO (IdPago)
);

/* llenamos los datos de la tabla Clientes */

Insert into TBLCLIENTES Values(1,'Ines serna',43990234,'calle 105


A','5224266','ines@gmail.com');
Insert into TBLCLIENTES Values(2,'gildardo moreno',72967234,'calle
10','5234533','tato@gmail.com');
Insert into TBLCLIENTES Values(3,'hosman janover',3423423,'calle
54','54534534','hosman@gmail.com');
Insert into TBLCLIENTES Values(4,'Cesar andres',6453544,'carrera
103','53534522','andres@gamil.com');
Insert into TBLCLIENTES Values(5,'adrian cano',354353453,'calle
104B','52851008','adrian@gmail.com');
Insert into TBLCLIENTES Values(6,'walter serna',64645644,'carrera
35','46456534','walter@gmail.com');
Insert into TBLCLIENTES Values(7,'enrique muñoz',53578978,'diagona
4','97973452','enrique@gmail.com');
Insert into TBLCLIENTES Values(8,'tatiana osorio',53453434,'circular
19','86745211','tatiana@gmail.com');
Insert into TBLCLIENTES Values(9,'cristina',56455573,'calle
24','11213123','cris@gmail.com');
Insert into TBLCLIENTES Values(10,'jessica susa',2342342,'carrela
55','67566345','jessi@gmail.com');

/* llenamos los datos de la tabla vendedor */

Insert into TBLVENDEDOR Values(1,'hosman janover',3423423,'calle


54','54534534','hosman@gmail.com');
Insert into TBLVENDEDOR Values(2,'adrian cano',354353453,'calle
104B','52851008','adrian@gmail.com');
Insert into TBLVENDEDOR Values(3,'gildardo moreno',72967234,'calle
10','5234533','tato@gmail.com');
Insert into TBLVENDEDOR Values(4,'Ines serna',43990234,'calle 105
A','5224266','ines@gmail.com');
Insert into TBLVENDEDOR Values(5,'enrique muñoz',53578978,'diagona
4','97973452','enrique@gmail.com');
Insert into TBLVENDEDOR Values(6,'Cesar andres',6453544,'carrera
103','53534522','andres@gamil.com');
Insert into TBLVENDEDOR Values(7,'walter serna',64645644,'carrera
35','46456534','walter@gmail.com');
Insert into TBLVENDEDOR Values(8,'jessica susa',2342342,'carrela
55','67566345','jessi@gmail.com');
Insert into TBLVENDEDOR Values(9,'tatiana osorio',53453434,'circular
19','86745211','tatiana@gmail.com');
Insert into TBLVENDEDOR Values(10,'cristina',56455573,'calle
24','11213123','cris@gmail.com');

Insert into TBLPROVEEDOR Values(1,'linda parra',3423423,'calle


54','54534534','hosman@gmail.com');
Insert into TBLPROVEEDOR Values(2,'adriana cano',354353453,'calle
104B','52851008','adrian@gmail.com');
Insert into TBLPROVEEDOR Values(3,'tina moreno',72967234,'calle
10','5234533','tato@gmail.com');
Insert into TBLPROVEEDOR Values(4,'juan serna',43990234,'calle 105
A','5224266','ines@gmail.com');
Insert into TBLPROVEEDOR Values(5,'miguel muñoz',53578978,'diagona
4','97973452','enrique@gmail.com');
Insert into TBLPROVEEDOR Values(6,'andrea sanchez',6453544,'carrera
103','53534522','andres@gamil.com');
Insert into TBLPROVEEDOR Values(7,'windi serna',64645644,'carrera
35','46456534','walter@gmail.com');
Insert into TBLPROVEEDOR Values(8,'jeison susa',2342342,'carrela
55','67566345','jessi@gmail.com');
Insert into TBLPROVEEDOR Values(9,'luis osorio',53453434,'circular
19','86745211','tatiana@gmail.com');
Insert into TBLPROVEEDOR Values(10,'cristian',56455573,'calle
24','11213123','cris@gmail.com');

/* llenamos los datos de la tabla pago */

Insert into TBLPAGO Values(1,'Efectivo');


Insert into TBLPAGO Values(2,'Credito');
Insert into TBLPAGO Values(3,'Devito');

/* llenamos los datos de la tabla Categoria */

Insert into TBLCATEGORIA Values(1,'Arroz');


Insert into TBLCATEGORIA Values(2,'Panela');
Insert into TBLCATEGORIA Values(3,'Aceite');
Insert into TBLCATEGORIA Values(4,'Chocolate');
Insert into TBLCATEGORIA Values(5,'Frijol');
Insert into TBLCATEGORIA Values(6,'Manteqilla');
Insert into TBLCATEGORIA Values(7,'Papel Hijienico');
Insert into TBLCATEGORIA Values(8,'Deterjente');
Insert into TBLCATEGORIA Values(9,'Jabon de Baño');
Insert into TBLCATEGORIA Values(10,'desodorante');
/* llenamos los datos de la tabla Caja */

Insert into TBLCAJA Values(1,'CAJA 1');


Insert into TBLCAJA Values(2,'CAJA 2');
Insert into TBLCAJA Values(3,'CAJA 3');
Insert into TBLCAJA Values(4,'CAJA 4');
Insert into TBLCAJA Values(5,'CAJA 5');
Insert into TBLCAJA Values(6,'CAJA 6');
Insert into TBLCAJA Values(7,'CAJA 7');
Insert into TBLCAJA Values(8,'CAJA 8');
Insert into TBLCAJA Values(9,'CAJA 9');
Insert into TBLCAJA Values(10,'CAJA 10');

/* llenamos los datos de la tabla Caja */

Insert Into TBLPRODUCTO VALUES (1,'Arroz Roa x 500g','arr001',1800,1,'unidad',150);


Insert Into TBLPRODUCTO VALUES (2,'Arroz Caribe x
500g','arr012',1800,1,'unidad',120);
Insert Into TBLPRODUCTO VALUES (3,'panela Valluna x
500g','pan001',1500,2,'unidad',100);
Insert Into TBLPRODUCTO VALUES (4,'Panela Regional x
500g','Pan011',1200,2,'unidad',130);
Insert Into TBLPRODUCTO VALUES (5,'Aceite Ricapalma x
350cm','ace009',3000,3,'unidad',100);
Insert Into TBLPRODUCTO VALUES (6,'Aceite Gourmet x
500cm','ace001',9000,3,'unidad',100);
Insert Into TBLPRODUCTO VALUES (7,'Chocolate cruz x
500g','cho001',3500,4,'unidad',900);
Insert Into TBLPRODUCTO VALUES (8,'Chocolate Luker x
500cm','cho003',9000,4,'unidad',100);
Insert Into TBLPRODUCTO VALUES (9,'Frijol Lima x
500cm','fri013',3000,5,'unidad',900);
Insert Into TBLPRODUCTO VALUES (10,'Frijol Cargamanto x
500cm','fri003',3500,5,'unidad',800);
Insert Into TBLPRODUCTO VALUES (11,'Mantequilla rama x
500cm','man006',9000,6,'unidad',100);
Insert Into TBLPRODUCTO VALUES (12,'Mantequilla La fina x
500cm','mano003',9000,6,'unidad',100);
Insert Into TBLPRODUCTO VALUES (13,'Papel Familia x 6
rollos','cho003',9000,7,'unidad',500);
Insert Into TBLPRODUCTO VALUES (14,'Ariel x 500cm','deto003',7000,8,'unidad',200);
Insert Into TBLPRODUCTO VALUES (15,'Fab x 500cm','det003',7500,8,'unidad',2500);
Insert Into TBLPRODUCTO VALUES (16,'Jabón baño
Palmolive','jab003',2500,9,'unidad',100);
Insert Into TBLPRODUCTO VALUES (17,'Jabobón Baño
Jhonson','jab005',9000,9,'unidad',100);
Insert Into TBLPRODUCTO VALUES (18,'desodorante
rexona','des003',800,10,'sobre',2500);
Insert Into TBLPRODUCTO VALUES (19,'desodorante speed','des023',800,10,'sobre',100);
Insert Into TBLPRODUCTO VALUES (20,'desodorante Axe','des005',1000,10,'Sobre',100);

/* llenamos los datos de la tabla Compra */

Insert into TBLCOMPRA Values(1,'F-2001','2020-03-12',1600,1,1,390);


Insert into TBLCOMPRA Values(2,'8654','2020-03-12',2000,2,3,250);
Insert into TBLCOMPRA Values(3,'345345','2020-03-12',2800,3,4,600);
Insert into TBLCOMPRA Values(4,'324324','2020-03-12',3000,4,7,400);
Insert into TBLCOMPRA Values(5,'23432- 5','2020-03-12',2500,5,9,430);
Insert into TBLCOMPRA Values(6,'24323','2020-03-12',1200,6,2,200);
Insert into TBLCOMPRA Values(7,'242343','2020-03-12',1500,7,4,500);
Insert into TBLCOMPRA Values(8,'88657-3','2020-03-12',2800,8,6,500);
Insert into TBLCOMPRA Values(9,'2342','2020-03-12',1000,9,8,240);
Insert into TBLCOMPRA Values(11,'21423','2020-03-12',800,10,10,300);
Insert into TBLCOMPRA Values(12,'F-2001','2020-03-12',1600,1,11,300);
Insert into TBLCOMPRA Values(13,'8654','2020-03-12',2000,2,12,600);
Insert into TBLCOMPRA Values(14,'345345','2020-03-12',2800,3,14,340);
Insert into TBLCOMPRA Values(15,'324324','2020-03-12',3200,4,16,900);
Insert into TBLCOMPRA Values(16,'23432- 5','2020-03-12',2500,5,18,600);
Insert into TBLCOMPRA Values(17,'24323','2020-03-12',1200,6,20,230);
Insert into TBLCOMPRA Values(18,'242343','2020-03-12',1500,7,13,400);
Insert into TBLCOMPRA Values(19,'88657-3','2020-03-12',2900,8,17,500);
Insert into TBLCOMPRA Values(20,'2342','2020-03-12',900,9,19,200);
Insert into TBLCOMPRA Values(21,'278723','2020-03-12',750,10,1,200);
Insert into TBLCOMPRA Values(22,'F-2001','2020-03-12',1550,1,3,250);
Insert into TBLCOMPRA Values(23,'8654','2020-03-12',2100,2,5,400);
Insert into TBLCOMPRA Values(24,'345345','2020-03-12',2700,3,7,500);
Insert into TBLCOMPRA Values(25,'324324','2020-03-12',1000,4,9,300);
Insert into TBLCOMPRA Values(26,'23432- 5','2020-03-12',1850,5,11,300);
Insert into TBLCOMPRA Values(27,'24323','2020-03-12',2750,6,13,400);
Insert into TBLCOMPRA Values(28,'242343','2020-03-12',3000,7,17,300);
Insert into TBLCOMPRA Values(29,'23423','2020-03-12',2000,6,18,200);
Insert into TBLCOMPRA Values(30,'88657-3','2020-03-12',900,8,19,100);
Insert into TBLCOMPRA Values(31,'2342','2020-03-12',800,9,20,100);

/* llenamos los datos de la tabla factura */

Insert Into TBLFACTURA VALUES (1,'2019-11-8',1,1,1);


Insert Into TBLFACTURA VALUES (2,'2019-11-9',2,2,2);
Insert Into TBLFACTURA VALUES (3,'2019-11-10',3,3,3);
Insert Into TBLFACTURA VALUES (4,'2019-12-12',4,4,4);
Insert Into TBLFACTURA VALUES (5,'2019-12-6',5,5,5);
Insert Into TBLFACTURA VALUES (6,'2019-12-7',6,6,6);
Insert Into TBLFACTURA VALUES (7,'2020-01-8',7,7,7);
Insert Into TBLFACTURA VALUES (8,'2020-01-8',8,8,8);
Insert Into TBLFACTURA VALUES (9,'2020-01-8',9,9,9);
Insert Into TBLFACTURA VALUES (10,'2020-02-12',10,10,10);
Insert Into TBLFACTURA VALUES (11,'2020-02-12',1,1,1);
Insert Into TBLFACTURA VALUES (12,'2020-03-12',2,2,2);
Insert Into TBLFACTURA VALUES (13,'2020-03-12',3,3,3);
Insert Into TBLFACTURA VALUES (14,'2020-03-12',4,4,4);
Insert Into TBLFACTURA VALUES (15,'2020-03-12',5,5,5);
/* llenamos los datos de la tabla detallefactura */

Insert Into TBLDETALLEFACTURA VALUES (1,1,1,8,1800,1);


Insert Into TBLDETALLEFACTURA VALUES (2,2,3,1,2700,1);
Insert Into TBLDETALLEFACTURA VALUES (3,3,5,7,3200,1);
Insert Into TBLDETALLEFACTURA VALUES (4,4,7,2,3000,2);
Insert Into TBLDETALLEFACTURA VALUES (5,5,9,6,3900,2);
Insert Into TBLDETALLEFACTURA VALUES (6,6,11,3,2000,2);
Insert Into TBLDETALLEFACTURA VALUES (7,7,13,5,2000,2);
Insert Into TBLDETALLEFACTURA VALUES (8,8,15,4,4000,2);
Insert Into TBLDETALLEFACTURA VALUES (9,9,17,8,1800,2);
Insert Into TBLDETALLEFACTURA VALUES (10,10,19,1,1100,3);
Insert Into TBLDETALLEFACTURA VALUES (11,11,2,7,1900,3);
Insert Into TBLDETALLEFACTURA VALUES (12,12,4,2,2600,3);
Insert Into TBLDETALLEFACTURA VALUES (13,13,6,6,3200,1);
Insert Into TBLDETALLEFACTURA VALUES (14,14,8,3,3500,1);
Insert Into TBLDETALLEFACTURA VALUES (15,15,10,5,2000,1);
Insert Into TBLDETALLEFACTURA VALUES (16,1,12,4,1800,1);
Insert Into TBLDETALLEFACTURA VALUES (18,3,16,1,1800,1);
Insert Into TBLDETALLEFACTURA VALUES (19,4,18,7,2000,1);
Insert Into TBLDETALLEFACTURA VALUES (20,5,20,2,1100,1);
Insert Into TBLDETALLEFACTURA VALUES (21,6,1,6,1850,2);
Insert Into TBLDETALLEFACTURA VALUES (22,7,3,3,2600,2);
Insert Into TBLDETALLEFACTURA VALUES (23,8,5,5,3200,2);
Insert Into TBLDETALLEFACTURA VALUES (24,9,7,4,3000,2);
Insert Into TBLDETALLEFACTURA VALUES (25,10,9,8,3900,3);
Insert Into TBLDETALLEFACTURA VALUES (26,11,11,1,2000,3);
Insert Into TBLDETALLEFACTURA VALUES (27,12,13,7,2000,2);
Insert Into TBLDETALLEFACTURA VALUES (28,13,15,2,4000,2);
Insert Into TBLDETALLEFACTURA VALUES (29,14,17,6,1750,2);
Insert Into TBLDETALLEFACTURA VALUES (30,15,19,3,1200,1);
Insert Into TBLDETALLEFACTURA VALUES (31,1,2,5,1850,1);
Insert Into TBLDETALLEFACTURA VALUES (32,2,4,4,2800,1);
Insert Into TBLDETALLEFACTURA VALUES (33,3,6,9,3400,1);
Insert Into TBLDETALLEFACTURA VALUES (34,4,8,1,3000,2);
Insert Into TBLDETALLEFACTURA VALUES (35,5,10,8,4000,2);
Insert Into TBLDETALLEFACTURA VALUES (36,6,12,2,2500,2);
Insert Into TBLDETALLEFACTURA VALUES (37,7,14,7,2000,3);
Insert Into TBLDETALLEFACTURA VALUES (38,8,16,3,3900,3);
Insert Into TBLDETALLEFACTURA VALUES (39,9,18,6,1800,3);
Insert Into TBLDETALLEFACTURA VALUES (40,10,20,4,1000,1);
Insert Into TBLDETALLEFACTURA VALUES (41,11,1,5,1800,1);
Insert Into TBLDETALLEFACTURA VALUES (42,12,3,9,2750,1);
Insert Into TBLDETALLEFACTURA VALUES (43,13,5,1,3200,2);
Insert Into TBLDETALLEFACTURA VALUES (44,14,7,8,2900,2);
Insert Into TBLDETALLEFACTURA VALUES (45,15,9,2,3800,1);
Insert Into TBLDETALLEFACTURA VALUES (46,1,11,7,2400,1);
Insert Into TBLDETALLEFACTURA VALUES (47,2,13,3,1800,1);
Insert Into TBLDETALLEFACTURA VALUES (48,3,15,6,3700,2);
Insert Into TBLDETALLEFACTURA VALUES (49,4,17,4,1900,1);
Insert Into TBLDETALLEFACTURA VALUES (50,5,19,5,900,1);
Insert Into TBLDETALLEFACTURA VALUES (51,6,2,9,1800,2);
Insert Into TBLDETALLEFACTURA VALUES (52,7,4,1,2700,3);
Insert Into TBLDETALLEFACTURA VALUES (53,8,6,8,3500,1);
Insert Into TBLDETALLEFACTURA VALUES (54,9,8,2,3400,2);
Insert Into TBLDETALLEFACTURA VALUES (55,10,10,7,3900,1);
Insert Into TBLDETALLEFACTURA VALUES (56,11,12,3,2500,1);
Insert Into TBLDETALLEFACTURA VALUES (57,12,14,6,2000,1);
Insert Into TBLDETALLEFACTURA VALUES (58,13,16,4,4000,2);
Insert Into TBLDETALLEFACTURA VALUES (59,14,18,5,2200,2);
Insert Into TBLDETALLEFACTURA VALUES (60,15,20,9,1100,3);
Insert Into TBLDETALLEFACTURA VALUES (61,1,1,1,1800,3);
Insert Into TBLDETALLEFACTURA VALUES (62,2,3,8,2700,1);
Insert Into TBLDETALLEFACTURA VALUES (63,3,5,2,3500,1);
Insert Into TBLDETALLEFACTURA VALUES (64,4,7,7,3400,1);
Insert Into TBLDETALLEFACTURA VALUES (65,5,9,3,3900,2);
Insert Into TBLDETALLEFACTURA VALUES (66,6,11,6,2500,1);
Insert Into TBLDETALLEFACTURA VALUES (67,7,13,4,2000,1);
Insert Into TBLDETALLEFACTURA VALUES (68,8,15,5,4000,2);
Insert Into TBLDETALLEFACTURA VALUES (69,9,17,9,2200,3);
Insert Into TBLDETALLEFACTURA VALUES (70,10,19,1,1100,3);
Insert Into TBLDETALLEFACTURA VALUES (71,11,2,8,1900,3);
Insert Into TBLDETALLEFACTURA VALUES (72,12,4,2,2600,1);
Insert Into TBLDETALLEFACTURA VALUES (73,13,6,7,3200,1);
Insert Into TBLDETALLEFACTURA VALUES (74,14,8,3,3000,3);
Insert Into TBLDETALLEFACTURA VALUES (75,15,10,6,3700,2);

/* ahora realizamos unas consultas para modificar los datos de las tablas*/

select * from TBLVENDEDOR

/*podemos ver que la tabla del vendedor, no tiene la información del salario, vamos
a modificar la tabla para agregar los datos */

Alter Table TBLVENDEDOR add Salario int;

select * from TBLVENDEDOR

/* ahora llenamos el salario de los empleados con update asi */

update TBLVENDEDOR SET Salario = 850000 where IdVendedor = 1;


update TBLVENDEDOR SET Salario = 870000 where IdVendedor = 2;
update TBLVENDEDOR SET Salario = 870000 where IdVendedor = 3;
update TBLVENDEDOR SET Salario = 850000 where IdVendedor = 4;
update TBLVENDEDOR SET Salario = 900000 where IdVendedor = 5;
update TBLVENDEDOR SET Salario = 900000 where IdVendedor = 6;
update TBLVENDEDOR SET Salario = 850000 where IdVendedor = 7;
update TBLVENDEDOR SET Salario = 870000 where IdVendedor = 8;
update TBLVENDEDOR SET Salario = 870000 where IdVendedor = 9;
update TBLVENDEDOR SET Salario = 850000 where IdVendedor = 10;
select * from TBLVENDEDOR

/*actualizamos la fecha de una factura */


update tblFactura set Dtmfecha = '2019-11-11' where idfactura = 03

/*borramos un producto de una venta */


select * from TBLDETALLEFACTURA order by idfactura
delete TBLDETALLEFACTURA where idproducto = 12 and Idfactura= 1;
select * from TBLDETALLEFACTURA order by idfactura

/* cambiamos elprecio de compra de un producto */


select * from tblCompra order by NumFactura
update tblCompra set PrecioCompra = 1500 where NumFactura = 2342 and IdProducto = 8
select * from tblCompra order by NumFactura
/*producto más costoso*/
select top 1*from tblProducto order by NumPrecioVenta desc

/*producto más barato*/


select top 1*from tblProducto order by NumPrecioVenta asc

/*Cuenta cuantas compras a realizado un cliente (usamos inner join, count y group
by)*/
select * from TBLFACTURA
select TBLFACTURA.IdCliente, TBLCLIENTES.NomCliente, count (TBLFACTURA.IdCliente) as
'Cant compras' from TBLFACTURA
join TBLCLIENTES ON TBLFACTURA.IdCliente=TBLCLIENTES.IdCliente group by
TBLFACTURA.IdCliente,TBLCLIENTES.NomCliente

/*Muestra los 4 empleados con mayor salario*/


select top 4 NomVendedor,Salario from TBLVENDEDOR order by Salario desc

/*empleados con salario mayor a 870000*/


select NomVendedor,Salario from TBLVENDEDOR where (salario > 870000)

/*Cuenta cuantas compras a realizado un vendedor (usamos inner join, count y group
by)*/
select * from TBLFACTURA
select TBLFACTURA.IdVendedor, TBLVENDEDOR.NomVendedor, count (TBLFACTURA.IdCliente)
as 'Cant ventas' from TBLFACTURA
join TBLVENDEDOR ON TBLFACTURA.IdVendedor=TBLVENDEDOR.IdVendedor group by
TBLFACTURA.IdVendedor,TBLVENDEDOR.NomVendedor

/*producto que mas se vende */


select top 1 TBLPRODUCTO.NomProducto, TBLDETALLEFACTURA.NumCantidad from TBLPRODUCTO
join TBLDETALLEFACTURA ON TBLPRODUCTO.IdProducto=TBLDETALLEFACTURA.IdProducto order
by TBLDETALLEFACTURA.NumCantidad desc

/*producto que menos se vende*/


select top 1 TBLPRODUCTO.NomProducto, TBLDETALLEFACTURA.NumCantidad from TBLPRODUCTO
join TBLDETALLEFACTURA ON TBLPRODUCTO.IdProducto=TBLDETALLEFACTURA.IdProducto order
by TBLDETALLEFACTURA.NumCantidad asc

También podría gustarte