Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

SQL server 2008 (build 10.0.5500): Why a table with Non-clustered index takes more space then another same table with a clustered index on the same column

$
0
0

Quite strange . 

CREATE TABLE [dbo].[test](
[i] [int] NOT NULL,
PRIMARY KEY CLUSTERED 
(
[i] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[test2](
[i] [int] NULL
) ON [PRIMARY]

GO

CREATE UNIQUE NONCLUSTERED INDEX [i] ON [dbo].[test2] 

(
[i] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

Insert 1000000 records in both the tables. You will notice that the second table takes much more space than the first table.

looking at sys.sysindexes shows that clustered index has 'y' pages (indid 1) whereas nonclustered index has 'y' pages for heap(indid 0) PLUS almost 1.4 x 'y' pages for indid 2 which is Non-clustered index.

Is this the same behavior that you are noticing in SQL Server 2005\2012 as well  . If yes then why ??

Regards

Abhay


Abhay Chaudhary OCP 9i, MCTS/MCITP (SQL Server 2005, 2008, 2005 BI) ms-abhay.blogspot.com/


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>