Professional Documents
Culture Documents
Implementing Table
Structures in
SQL Server 2012
Module Overview
SQL Server Table Structures
Working with Clustered Indexes
Designing Effective Clustered Indexes
What is a Heap?
A table with:
No specified order for pages within the table
No specified order for data within each page
Data that is inserted or modified can be placed anywhere
index_id=0
first_iam_page
IAM Page
Heap
Heap
Data Pages
Operations on Heaps
INSERT
Each new row can be placed in the first available page with
sufficient space
UPDATE
The row can either remain on the same page if it still fits,
otherwise, it can be removed from the current page and
placed on the first available page with sufficient space
DELETE
SELECT
Forwarding Pointers
Forwarding
Forwarding pointers
pointers are
are references
references left
left at
at the
the original
original location
location
of
of a
a row,
row, when
when the
the row
row has
has been
been moved.
moved.
Data modifications in heaps can leave forwarding pointers
id
index_id=1
root_page
Root Index
Page
Index Pages
Data Pages
Each new row must be placed into the correct logical position
UPDATE
The row can either remain in the same place if it still fits and if the
clustering key value is still the same
If the row no longer fits on the page, the page needs to be split
DELETE
SELECT
Queries related to the clustering key can scan and avoid sorts
non-unique indexes
Rebuild a heap
DROP
DROP INDEX
INDEX CL_LogTime
CL_LogTime ON
ON dbo.LogTime;
dbo.LogTime;
ALTER
ALTER TABLE dbo.LogData
dbo.LogData
DROP CONSTRAINT PK_LogData;
PK_LogData;
Can DISABLE
ALTER
ALTER INDEX
INDEX CL_LogTime
CL_LogTime ON
ON dbo.LogTime
dbo.LogTime
REBUILD;
REBUILD;
ALTER
ALTER INDEX
INDEX ALL
ALL ON
ON dbo.LogTime
dbo.LogTime
REBUILD;
REBUILD;
ALTER
ALTER INDEX
INDEX ALL
ALL ON
ON dbo.LogTime
dbo.LogTime
REORGANIZE;
REORGANIZE;
FILLFACTOR
PAD_INDEX
ALTER
ALTER TABLE
TABLE Person.Contact
Person.Contact
ADD
ADD CONSTRAINT
CONSTRAINT PK_Contact_ContactID
PK_Contact_ContactID
PRIMARY
PRIMARY KEY
KEY CLUSTERED
CLUSTERED
(
(
ContactID
ContactID ASC
ASC
)
) WITH
WITH (PAD_INDEX
(PAD_INDEX =
= OFF,
OFF, FILLFACTOR
FILLFACTOR = 70);
70);
GO
GO
Short
Static
Unique
16 columns
900 bytes
Data Type
Comments
int
bigint
date
smalldatetime
Logon information
Virtual machine
10776A-MIA-SQL1
User name
AdventureWorks\Administrator
Password
Pa$$w0rd
Lab Scenario
One of the most important decisions when designing a table
is to choose an appropriate table structure. In this lab, you
will choose an appropriate structure for some new tables
required for the relationship management system.
Lab Review
When is it important that a clustered index has an
increasing key?