SQL primary key add INCLUDE column

Posted on 2009-07-15
Last Modified: 2012-05-07
I have a table with a GUID primary key, is it possible to add INCLUDE fields to this cluster index, if so could you give me the syntax to alter this index as I do not want to delete it this would effect existing relationships with other tables etc. I know it is possible to add include fields to other indexes.
Question by:freshnet
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
  • 4
  • 3
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24858806
Hope this helps:
CREATE TABLE test ( a uniqueidentifier PRIMARY key, b int, c int);
CREATE nonCLUSTERED INDEX ix_test ON test ( a) INCLUDE (b,c)

Open in new window

LVL 60

Expert Comment

ID: 24858846
BTW...if your primary key is clustered, you will not need to include a column. By default, all columns in a clustered index are "included" this would only apply to an NC primary key
LVL 60

Expert Comment

ID: 24858857
rrjegan, your example really isn't default the primary key is clustered unless you specify otherwise.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 57

Accepted Solution

Raja Jegan R earned 500 total points
ID: 24858945
>> rrjegan, your example really isn't applicable

I misread the question. Thanks for pointing it out.


>> is it possible to add INCLUDE fields to this cluster index
   No.. You cant create clustered index with INCLUDE clause.

Hope this clarifies.
LVL 60

Expert Comment

ID: 24858955
No worries.  Just wanted to clear it up.  :)

Author Closing Comment

ID: 31603708
but why is this do you think?
LVL 60

Expert Comment

ID: 24859653
pretty sure a split would have been necessary here....
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24859752
For your reference,

INCLUDE ( column [ ,... n ] )
    Specifies the non-key columns to be added to the leaf level of the nonclustered index. The nonclustered index can be unique or non-unique.
    Column names cannot be repeated in the INCLUDE list and cannot be used simultaneously as both key and non-key columns. Nonclustered indexes always contain the clustered index columns if a clustered index is defined on the table. For more information, see Index with Included Columns.

>> pretty sure a split would have been necessary here....

No concerns from my side as you directed me correctly.

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 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