Sunteți pe pagina 1din 3

create database NorthWind_Mart; Use NorthWind_Mart; DROP TABLE Customer_Dim create table Customer_Dim ( CustomerKey int IDENTITY, Phone

nchar(24) null, Fax nchar(24) null, Region nchar(50) null, PostalCode nchar(10) null, Country nchar(15) null, ContactTitle nchar(40) not null, Address nchar(60) not null, City nchar(15) not null, CustomerID nchar(5) not null, CompanyName nchar(50) Not null, ContactName nchar(40) null, primary key (CustomerKey) ) --drop table Product_Dim Use NorthWind_Mart; create table Product_Dim ( ProductKey int IDENTITY, ProductName nchar(40) not null, SupplierName nchar(40) not null, CategoryName nchar(15) not null, ProductID int not null, ListUnitPrice money not null, primary key (ProductKey) )

--drop table Shipper_dim Use NorthWind_Mart; create table Shipper_dim ( ShipperKey int ShipperName nchar(40) ShipperID int primary key (ShipperKey) ) --drop table Time_Dim Use NorthWind_Mart; create table Time_Dim ( TimeKey YearMonth DayOfWeef

IDENTITY, not null, not null,

int nchar(15) nchar(10)

IDENTITY, not null, not null,

Holiday WeekEnd Quarter DayOfYear WeekOfYear Month Year TheDate primary key (TimeKey) )

nchar not null, nchar not null, int not int not int not int not int not datetime not

null, null, null, null, null, null,

Use NorthWind_Mart; --drop table Employee_Dim create table Employee_Dim ( EmployeeKey int IDENTITY, EmplotyeeName nchar(40) not null, EmployeeID int not null, HireDate datetime null, primary key (EmployeeKey) ) --drop table Sales_Fact Use NorthWind_Mart; create table Sales_Fact ( ProductKey int not null, EmployeeKey int not null, TimeKey int not null, CustomerKey int not null, ShipperKey int not null, LineItemDiscount money not null, LineItemQuantity smallint null, LineItemFreight money not null, LineItemTotal money not null, RaquiredDate datetime not null, primary key (ProductKey,EmployeeKey, TimeKey,CustomerKey,ShipperKey) )

alter table dbo.Sales_Fact ADD CONSTRAINT sales_TimeKey FOREIGN KEY (TimeKey) REFERENCES dbo.Time_dim(Timekey) alter table dbo.Sales_Fact ADD CONSTRAINT sales_ProductKey FOREIGN KEY (ProductKey) REFERENCES dbo.Product_dim(ProductKey) alter table dbo.Sales_Fact ADD CONSTRAINT sales_EmployeeKey FOREIGN KEY (EmployeeKey) REFERENCES dbo.Employee_dim(EmployeeKey) alter table dbo.Sales_Fact ADD CONSTRAINT sales_CustomerKey FOREIGN KEY (CustomerKey) REFERENCES dbo.Customer_dim(CustomerKey)

alter table dbo.Sales_Fact ADD CONSTRAINT sales_ShipperKey FOREIGN KEY (ShipperKey) REFERENCES dbo.Shipper_dim(ShipperKey) select * from Northwind.dbo.Shippers select * from Shipper_dim -- Poblando tabla de Transportistas (Shippers) insert into Shipper_dim (ShipperName,ShipperId) select CompanyName, ShipperId from northwind.dbo.Shippers -/*Carga Empleados*/ select * from Employee_Dim INSERT into Employee_Dim(EmployeeID, EmplotyeeName, HireDate) SELECT EmployeeID, LastName + ','+ FirstName AS CompanyName, HireDate FROM NorthWind.dbo.Employees /*Carga Clientes*/ select * from Customer_Dim INSERT into Customer_Dim(CustomerID,CompanyName,ContactName, Address,City,Country,Region,ContactTitle,PostalCode,Phone,Fax) SELECT CustomerID,CompanyName,ContactName, Address,City,Country,Region,ContactTitle,PostalCode,Phone,Fax FROM NorthWind.dbo.Customers select * from Shipper_dim INSERT into Shipper_Dim (ShipperID,ShipperName) SELECT ShipperID,CompanyName FROM NorthWind.dbo.Shippers delete Shipper_dim DBCC CHECKIDENT(Shipper_Dim,reseed,0)

S-ar putea să vă placă și