Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Want to Convert PRIMARY KEY from NONCLUSTERED TO CLUSTERED pls Advice !! Expand / Collapse
Author
Message
Posted Tuesday, July 8, 2014 5:49 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: 2 days ago @ 10:10 AM
Points: 85, Visits: 217
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
Post #1590310
Posted Tuesday, July 8, 2014 6:06 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:50 AM
Points: 1,117, Visits: 1,375
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
Post #1590316
Posted Tuesday, July 8, 2014 6:11 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:15 AM
Points: 13,642, Visits: 10,535
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1590321
Posted Tuesday, July 8, 2014 6:17 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 5:50 AM
Points: 1,117, Visits: 1,375
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
Post #1590324
Posted Tuesday, July 8, 2014 8:07 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: 2 days ago @ 10:10 AM
Points: 85, Visits: 217
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
Post #1590376
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse