Sistemas
ESFOT- ASI
BASES DE DATOS I
-------------------------------------------------
Ejercicios de clase presencial para Select Básicos y soluciones para las tablas:CABFACT (NoCabFac(PK), FechaCabFac, CodCli)
DETALLEFACTURA (CodDetal (PK), CodProd(FK), Cantidad,NoCabFac(FK))
PRODUCTOS(CodProd(PK),DetalProd,StockProd,PuProd,PvProd)
Create Database LaboSelect
UseLaboSelect
Create table CABFACT
(NoCabFac numeric (4) primary key,
FechaCabFac date,
CodCli varchar(4))
Create table PRODUCTOS
(CodProd varchar(4) primary key,
DetalProd varchar (30),StockProd numeric (5),
PuProd smallmoney,
PvProd smallmoney)
Create table DETALLEFACTURA
(CodDetal numeric (6) IDENTITY,
CodProdFK varchar (4) foreign key references Productos (CodProd),CantiDetal numeric (4),
NoCabFacFK numeric (4) foreign key references CabFact (NoCabFac))
Select * from PRODUCTOS
select * from CABFACT
select * from DETALLEFACTURA
EJERCICIOS
* seleccionarcolumnas de varias tablas */
select * from cabfact
select * from detallefactura
select *
from cabfact, detallefactura,productos
where numfact=numfactfk
and codprod=codprodfk
/*seleccionar algunos campos*/
select * from productos
select impprod, nomprod, stockprod
from productos
/* operaciones matemáticas: obtener el nombre del producto, stock,
precio unitario yprecio total por producto*/
select nomprod, stockprod, puprod, puprod*stockprod
from productos
/* poner nombre a las columnas */
select nomprod, stockprod, puprod,preciototal=puprod*stockprod
from productos
select nomprod, stockprod, puprod, puprod*stockprod as preciototal2
from productos
/* todos los datos de cada factura incluido el valor por factura */
select *,totalfactura=stockprod*puprod
from cabfact, detallefactura,productos
where numfact=numfactfk
and codprod=codprodfk
/* usando campos fecha */
create table tabfecha
(fecha datetime)
insert ...
Regístrate para leer el documento completo.