0% found this document useful (0 votes)
17 views14 pages

Electiva Almacen de Datos

The document describes the creation of database tables and relationships for a data warehouse using SQL Server. It includes the creation of dimension tables such as dates, customers, products, and fact tables for orders and order details along with the primary and foreign keys to link them.

Uploaded by

Ocean World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views14 pages

Electiva Almacen de Datos

The document describes the creation of database tables and relationships for a data warehouse using SQL Server. It includes the creation of dimension tables such as dates, customers, products, and fact tables for orders and order details along with the primary and foreign keys to link them.

Uploaded by

Ocean World
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

INSTITUTO TECNOLÓGICO DE LAS AMÉRICAS

TECNOLOGÍA EN DESARROLLO
DE SOFTWARE
ASIGNATURA: Electiva 1
Nombre:
Andy Augusto Encarnacion M
Matricula:
2022-0995
Profesor:
Francis Ramirez
Tema:
Almacen de datos
-- --------------------------------------------------

-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure

-- --------------------------------------------------

-- Date Created: 03/18/2024 19:41:45

-- Generated from EDMX file:


D:\Northwind\NorthWind\NorthWind.ConceptualModel\Models\NorthwindModel.edmx

-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;

GO

USE [Northwind];

GO

IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');

GO
-- --------------------------------------------------

-- Dropping existing FOREIGN KEY constraints

-- --------------------------------------------------

-- --------------------------------------------------

-- Dropping existing tables

-- --------------------------------------------------

-- --------------------------------------------------

-- Creating all tables

-- --------------------------------------------------

-- Creating table 'DimDates'

CREATE TABLE [dbo].[DimDates] (

[DateKey] int IDENTITY(1,1) NOT NULL,

[Date] datetime NOT NULL,

[DateName] nvarchar(max) NOT NULL,

[Month] int NOT NULL,

[MonthName] nvarchar(50) NOT NULL,

[Quarter] int NOT NULL,

[QuarterName] nvarchar(50) NOT NULL,

[Year] int NOT NULL,

[YearName] nvarchar(50) NOT NULL

);

GO

-- Creating table 'DimShippers'

CREATE TABLE [dbo].[DimShippers] (

[ShipperKey] int IDENTITY(1,1) NOT NULL,


[ShipperId] int NOT NULL,

[ShipperName] nvarchar(40) NOT NULL

);

GO

-- Creating table 'DimCustomers'

CREATE TABLE [dbo].[DimCustomers] (

[CustomerKey] int IDENTITY(1,1) NOT NULL,

[CustomerId] nvarchar(5) NOT NULL,

[CustomerName] nvarchar(40) NOT NULL

);

GO

-- Creating table 'DimProducts'

CREATE TABLE [dbo].[DimProducts] (

[ProductKey] int IDENTITY(1,1) NOT NULL,

[ProductId] int NOT NULL,

[ProductName] nvarchar(40) NOT NULL,

[CategoryId] int NOT NULL,

[CategoryName] nvarchar(15) NOT NULL,

[DimCategoriesCategoryKey] int NOT NULL

);

GO

-- Creating table 'DimEmployees'

CREATE TABLE [dbo].[DimEmployees] (

[EmployeesKey] int IDENTITY(1,1) NOT NULL,

[EmployeesId] int NOT NULL,

[EmployeesName] nvarchar(10) NOT NULL

);

GO
-- Creating table 'FactOrder'

CREATE TABLE [dbo].[FactOrder] (

[OrderId] int IDENTITY(1,1) NOT NULL,

[CustomerKey] int NOT NULL,

[DateKey] int NOT NULL,

[EmployeeKey] int NOT NULL,

[ShipperKey] int NOT NULL,

[DimCustomersCustomerKey] int NOT NULL,

[DimDatesDateKey] int NOT NULL,

[DimShippersShipperKey] int NOT NULL,

[DimEmployeesEmployeesKey] int NOT NULL,

[FactOrderDetailsID] int NOT NULL

);

GO

-- Creating table 'FactOrderDetails'

CREATE TABLE [dbo].[FactOrderDetails] (

[ID] int IDENTITY(1,1) NOT NULL,

[OrderId] int NOT NULL,

[ProductsKey] int NOT NULL,

[Total] decimal(19,2) NOT NULL,

[Quantity] decimal(19,2) NOT NULL,

[DimProductsProductKey] int NOT NULL

);

GO

-- Creating table 'DimCategories'

CREATE TABLE [dbo].[DimCategories] (

[CategoryKey] int IDENTITY(1,1) NOT NULL,

[CategoryId] int NOT NULL,


[CategoryName] nvarchar(15) NOT NULL

);

GO

-- --------------------------------------------------

-- Creating all PRIMARY KEY constraints

-- --------------------------------------------------

-- Creating primary key on [DateKey] in table 'DimDates'

ALTER TABLE [dbo].[DimDates]

ADD CONSTRAINT [PK_DimDates]

PRIMARY KEY CLUSTERED ([DateKey] ASC);

GO

-- Creating primary key on [ShipperKey] in table 'DimShippers'

ALTER TABLE [dbo].[DimShippers]

ADD CONSTRAINT [PK_DimShippers]

PRIMARY KEY CLUSTERED ([ShipperKey] ASC);

GO

-- Creating primary key on [CustomerKey] in table 'DimCustomers'

ALTER TABLE [dbo].[DimCustomers]

ADD CONSTRAINT [PK_DimCustomers]

PRIMARY KEY CLUSTERED ([CustomerKey] ASC);

GO

-- Creating primary key on [ProductKey] in table 'DimProducts'

ALTER TABLE [dbo].[DimProducts]

ADD CONSTRAINT [PK_DimProducts]

PRIMARY KEY CLUSTERED ([ProductKey] ASC);

GO
-- Creating primary key on [EmployeesKey] in table 'DimEmployees'

ALTER TABLE [dbo].[DimEmployees]

ADD CONSTRAINT [PK_DimEmployees]

PRIMARY KEY CLUSTERED ([EmployeesKey] ASC);

GO

-- Creating primary key on [OrderId] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [PK_FactOrder]

PRIMARY KEY CLUSTERED ([OrderId] ASC);

GO

-- Creating primary key on [ID] in table 'FactOrderDetails'

ALTER TABLE [dbo].[FactOrderDetails]

ADD CONSTRAINT [PK_FactOrderDetails]

PRIMARY KEY CLUSTERED ([ID] ASC);

GO

-- Creating primary key on [CategoryKey] in table 'DimCategories'

ALTER TABLE [dbo].[DimCategories]

ADD CONSTRAINT [PK_DimCategories]

PRIMARY KEY CLUSTERED ([CategoryKey] ASC);

GO

-- --------------------------------------------------

-- Creating all FOREIGN KEY constraints

-- --------------------------------------------------

-- Creating foreign key on [DimProductsProductKey] in table 'FactOrderDetails'

ALTER TABLE [dbo].[FactOrderDetails]


ADD CONSTRAINT [FK_DimProductsFactOrderDetails]

FOREIGN KEY ([DimProductsProductKey])

REFERENCES [dbo].[DimProducts]

([ProductKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimProductsFactOrderDetails'

CREATE INDEX [IX_FK_DimProductsFactOrderDetails]

ON [dbo].[FactOrderDetails]

([DimProductsProductKey]);

GO

-- Creating foreign key on [DimCategoriesCategoryKey] in table 'DimProducts'

ALTER TABLE [dbo].[DimProducts]

ADD CONSTRAINT [FK_DimCategoriesDimProducts]

FOREIGN KEY ([DimCategoriesCategoryKey])

REFERENCES [dbo].[DimCategories]

([CategoryKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimCategoriesDimProducts'

CREATE INDEX [IX_FK_DimCategoriesDimProducts]

ON [dbo].[DimProducts]

([DimCategoriesCategoryKey]);

GO

-- Creating foreign key on [DimCustomersCustomerKey] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [FK_DimCustomersFactOrder]


FOREIGN KEY ([DimCustomersCustomerKey])

REFERENCES [dbo].[DimCustomers]

([CustomerKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimCustomersFactOrder'

CREATE INDEX [IX_FK_DimCustomersFactOrder]

ON [dbo].[FactOrder]

([DimCustomersCustomerKey]);

GO

-- Creating foreign key on [DimDatesDateKey] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [FK_DimDatesFactOrder]

FOREIGN KEY ([DimDatesDateKey])

REFERENCES [dbo].[DimDates]

([DateKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimDatesFactOrder'

CREATE INDEX [IX_FK_DimDatesFactOrder]

ON [dbo].[FactOrder]

([DimDatesDateKey]);

GO

-- Creating foreign key on [DimShippersShipperKey] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [FK_DimShippersFactOrder]

FOREIGN KEY ([DimShippersShipperKey])


REFERENCES [dbo].[DimShippers]

([ShipperKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimShippersFactOrder'

CREATE INDEX [IX_FK_DimShippersFactOrder]

ON [dbo].[FactOrder]

([DimShippersShipperKey]);

GO

-- Creating foreign key on [DimEmployeesEmployeesKey] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [FK_DimEmployeesFactOrder]

FOREIGN KEY ([DimEmployeesEmployeesKey])

REFERENCES [dbo].[DimEmployees]

([EmployeesKey])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DimEmployeesFactOrder'

CREATE INDEX [IX_FK_DimEmployeesFactOrder]

ON [dbo].[FactOrder]

([DimEmployeesEmployeesKey]);

GO

-- Creating foreign key on [FactOrderDetailsID] in table 'FactOrder'

ALTER TABLE [dbo].[FactOrder]

ADD CONSTRAINT [FK_FactOrderDetailsFactOrder]

FOREIGN KEY ([FactOrderDetailsID])

REFERENCES [dbo].[FactOrderDetails]
([ID])

ON DELETE NO ACTION ON UPDATE NO ACTION;

GO

-- Creating non-clustered index for FOREIGN KEY 'FK_FactOrderDetailsFactOrder'

CREATE INDEX [IX_FK_FactOrderDetailsFactOrder]

ON [dbo].[FactOrder]

([FactOrderDetailsID]);

GO

-- --------------------------------------------------

-- Script has ended

-- --------------------------------------------------

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy