Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Want to Convert PRIMARY KEY from NONCLUSTERED TO CLUSTERED pls Advice !!


Want to Convert PRIMARY KEY from NONCLUSTERED TO CLUSTERED pls Advice !!

Author
Message
prabhu.st
prabhu.st
SSC-Enthusiastic
SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)

Group: General Forum Members
Points: 114 Visits: 309
Friends,

Table Structure:

CREATE TABLE MappingTable (
[Column1] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[Column2] [int] NOT NULL,
[Column3] [int] NOT NULL,
[Column4] [bit] NULL,
[Column5] [datetime] NULL,
[Column6] [datetime] NULL,
CONSTRAINT [PK_MappingTable] PRIMARY KEY NONCLUSTERED
(
[Column2] ASC,
[Column3] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO



Now, my question is , I think to alter the table to PRIMARY KEY CLUSTERED, could you please suggest me, is there any difficulties or performance issue because of this changes.

Thanks,
Prabhu
Hardy21
Hardy21
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 1399
I hope it is not Live system as you have not mentioned about it.

You need to drop primary key & add it again with CLUSTERED clause as below


ALTER TABLE mappingTable DROP CONSTRAINT [PK_MappingTable]
ALTER TABLE mappingTable ADD CONSTRAINT [PK_MappingTable] PRIMARY KEY CLUSTERED
(
[Column2] ASC,
[Column3] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]



It will create Clustered Index. The clustered index has an advantage over all other indexes: since it always includes all columns, is always covering. Therefore queries that can leverage the clustered index certainly do not need to use lookups to satisfy some of the projected columns and/or predicates.

Thanks
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16467 Visits: 13207
Hardy21 (7/8/2014)

The clustered index has an advantage over all other indexes: since it always includes all columns, is always covering. Therefore queries that can leverage the clustered index certainly do not need to use lookups to satisfy some of the projected columns and/or predicates.


Yes, but if queries cannot leverage the clustered index, you are still doing a full table scan.



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Hardy21
Hardy21
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1204 Visits: 1399
Koen Verbeeck (7/8/2014)
Hardy21 (7/8/2014)

The clustered index has an advantage over all other indexes: since it always includes all columns, is always covering. Therefore queries that can leverage the clustered index certainly do not need to use lookups to satisfy some of the projected columns and/or predicates.


Yes, but if queries cannot leverage the clustered index, you are still doing a full table scan.

Thats is correct. It depends on how you query the data.

Thanks
prabhu.st
prabhu.st
SSC-Enthusiastic
SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)

Group: General Forum Members
Points: 114 Visits: 309
Thanks to Hardy & Koen for your immediate replies.

@Hardy,

yes it is not a live server as of now, but I am planning to implement the changes to the live server whereas it should be
tested in various stages

"Development Integration Server" (DIS)
"System Integration Server" (SIS)
"Performance Testing Server" (PTS)
Finally to the "Live Server" (Live)

@Koen,

yes, as of now since that is a mapping table and Column2 and Column3 refers to each Master Table respectively
and the values in these columns are the IDs of the appropriate master tables, thus these two columns has the vast usage and there is no point to think about "out of Leverage"

Thanks for all your Inputs, I would test this with my DIS first, then let you know for sure..

Cheers,
Prabhu
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search