Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

10777 - Dimension table indexes

Posted on 2014-07-18
1
Medium Priority
?
430 Views
Last Modified: 2014-07-22
Hi experts,

i am reading about
Dimension table indexes:
Create a nonclustered primary key index
Create a clustered business key index

but i do not understand
Create a nonclustered primary key index
why nonclustered?

this is the script
CREATE TABLE DimProduct
(ProductKey int identity NOT NULL PRIMARY KEY NONCLUSTERED,
 ProductAltKey nvarchar(10) NOT NULL,
 ProductName nvarchar(50) NULL,
 ProductDescription nvarchar(100) NULL,
 ProductCategoryName nvarchar(50))
GO

 CREATE TABLE DimGeography
 (GeographyKey int identity NOT NULL PRIMARY KEY NONCLUSTERED,
  PostalCode nvarchar(15) NULL,
  City nvarchar(50) NULL,
  Region nvarchar(50) NULL,
  Country nvarchar(50) NULL)
GO

 CREATE TABLE DimCustomer
(CustomerKey int identity NOT NULL PRIMARY KEY NONCLUSTERED,
 CustomerAltKey nvarchar(10) NOT NULL,
 CustomerName nvarchar(50) NULL,
 CustomerEmail nvarchar(50) NULL,
 CustomerGeographyKey int NULL REFERENCES DimGeography(GeographyKey))
GO


 CREATE TABLE DimSalesperson
(SalespersonKey int identity NOT NULL PRIMARY KEY NONCLUSTERED,
 SalesPersonAltKey nvarchar(10) NOT NULL,
 SalespersonName nvarchar(50) NULL,
 StoreName nvarchar(50) NULL,
 StoreGeographyKey int NULL REFERENCES DimGeography(GeographyKey))

 CREATE TABLE DimDate
 (DateKey int NOT NULL PRIMARY KEY NONCLUSTERED,
  DateAltKey datetime NOT NULL,
  CalendarYear int NOT NULL,
  CalendarQuarter int NOT NULL,
  MonthOfYear int NOT NULL,
  [MonthName] nvarchar(15) NOT NULL,
  [DayOfMonth] int NOT NULL,
  [DayOfWeek] int NOT NULL,
  [DayName] nvarchar(15) NOT NULL,
  FiscalYear int NOT NULL,
  FiscalQuarter int NOT NULL)
GO
  -- CREATE A FACT TABLE
  CREATE TABLE FactSalesOrders
  (ProductKey int NOT NULL REFERENCES DimProduct(ProductKey),
   CustomerKey int NOT NULL REFERENCES DimCustomer(CustomerKey),
   SalespersonKey int NOT NULL REFERENCES DimSalesperson(SalespersonKey),
   OrderDateKey int NOT NULL REFERENCES DimDate(DateKey),
   OrderNo int NOT NULL,
   ItemNo int NOT NULL,
   Quantity int NOT NULL,
   SalesAmount money NOT NULL,
   Cost money NOT NULL
    CONSTRAINT [PK_ FactSalesOrder] PRIMARY KEY NONCLUSTERED
 (
      [ProductKey],[CustomerKey],[SalesPersonKey],[OrderDateKey],[OrderNo],[ItemNo]
 )
 )
GO
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
Vikas Garg earned 1000 total points
ID: 40204318
Hi,

Type of indexing in dimension Tables

1) Apply clustered index on surrogate key & non-clustered index on natural key of the dimension which will help key lookup in the ETL process.

1st option is best if you use Analysis Services & MOLAP cube

2) Apply clustered index on the natural key and non-clustered index on the surrogate key.

2nd option is better to avoid lock escalation

Hope this would clear your doubts ....
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question