You are on page 1of 3

PRACTICA N° 3

Objetivos: Crear una BD y tablas DataWarehouse (DW)

1. Iniciar Microsoft SQL Server Managment Studio y conectar al servidor.

Nota: El nombre del servidor para nuestro caso es el nombre del computador, seguido del nombre de la
instancia el cuál se configuró en el momento de la instalación.

2. Vamos a crear una nueva consulta

3. Consulta:

Use master
go
--
if exists(select * from sysdatabases where name='OLTP_Stage')
drop database OLTP_Stage
go
--
create database OLTP_Stage
go
Use OLTP_Stage
go

--
create function dbo.fn_mes(@m int)returns varchar(15)
begin
declare @mes table(codigo int,nombre varchar(15))
insert @mes values(1,'Enero'),(2,'Febrero'),
(3,'Marzo'),(4,'Abril'),(5,'Mayo'),(6,'Junio'),
(7,'Julio'),(8,'Agosto'),(9,'Setiembre'),
(10,'Octubre'),(11,'Noviembre'),(12,'Diciembre')
return(select nombre from @mes where codigo=@m)
end
go
--
create function dbo.fn_diaSem(@d int)returns varchar(15)
begin
declare @semana table(codigo int,nombre varchar(15))
insert @semana values(1,'Lunes'),(2,'Martes'),
(3,'Miércoles'),(4,'Jueves'),(5,'Viernes'),
(6,'Sábado'),(7,'Domingo')
return(select nombre from @semana where codigo=@d)
end
go

/*------------------------------UBIGEO---------------------------------------
*/
create table DimUbigeo(
Ubigeo_SKey int identity (1,1) primary key not null,
IdDepartamento nchar(10) not null,
NombreDepartamento nvarchar(50) not null,
IdProvincia nchar(10) not null,
NombreProvincia nvarchar(50) not null,
IdDistrito nchar(10) not null,
NombreDistrito nvarchar(50) not null);
--Select * from DimUbigeo
/*------------------------------CLIENTE--------------------------------------
-*/
create table DimCliente(
ECliente int identity (1,1) primary key not null,
IdCliente nchar(6) not null,
NombreCliente nvarchar(150) not null,
IdDistrito nchar(10) not null,
NombreDistrito nvarchar(50) not null,
DniCliente nchar(8) not null);
--Select * from DimCliente

/*------------------------------EMPLEADO-------------------------------------
-*/
create table DimEmpleado(
EEmpleado int identity (1,1) primary key not null,
IdEmpleado nchar(6) not null,
NombreEmpleado nvarchar(150) not null,
IdDistrito nchar(10) not null,
NombreDistrito nvarchar(50) not null,
DniEmpleado nchar(8) not null);
--Select * from DimEmpleado

/*--------------------------------PRODUCTO----------------------------------
*/
create table DimProducto(
EProducto int identity (1,1) primary key not null,
IdProducto nchar(6) not null,
DescriProducto varchar(100) not null,
IdMarca nchar(6) not null,
NombreMarca nvarchar(50) not null,
IdCategoria nchar(6) not null,
NombreCategoria nvarchar(50) not null,
PrecioUnidad money null);
--Select * from DimProducto

/*------------------------------TIEMPO--------------------------------------
*/
create table DimTiempo (
FechaId int primary key not null,
Fecha datetime not null,
Año smallint not null,
Trimestre tinyint not null,
Mes tinyint not null,
NomMes varchar(15) not null,
Dia tinyint not null,
DiaSem tinyint not null,
NomDiaSem varchar(15) not null);
--Select * from DimTiempo

/*------------------------------VentaOrden-----------------------------------
---*/
create table FactVentaOrden (
ECliente int references DimCliente not null,
EEmpleado int references DimEmpleado not null,
Ubigeo_SKey int references DimUbigeo not null,
EProducto int references DimProducto not null,
FechaId int references DimTiempo not null,
Total money not null);
--Select * from FactVentaOrden

--alter table DimProducto alter column DescriProducto nvarchar(100) not null

4. Ejecuta r script (F5)

5. Actualizar y Refrescar (F5) Ahora debe aparecer la base de datos OLTP_Stage con las tablas
creadas, el siguiente paso es poblar cargar los datos a las tablas.

You might also like