Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

SQL primary key add INCLUDE column

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.
0
freshnet
Asked:
freshnet
  • 4
  • 3
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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

0
 
chapmandewCommented:
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"...so this would only apply to an NC primary key
0
 
chapmandewCommented:
rrjegan, your example really isn't applicable....by default the primary key is clustered unless you specify otherwise.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Raja Jegan RSQL Server DBA & ArchitectCommented:
>> rrjegan, your example really isn't applicable

I misread the question. Thanks for pointing it out.

freshnet,

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

Hope this clarifies.
0
 
chapmandewCommented:
No worries.  Just wanted to clear it up.  :)
0
 
freshnetAuthor Commented:
but why is this do you think?
0
 
chapmandewCommented:
pretty sure a split would have been necessary here....
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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.

http://msdn.microsoft.com/en-us/library/ms188783.aspx

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

No concerns from my side as you directed me correctly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now