Solved

SQL primary key add INCLUDE column

Posted on 2009-07-15
8
286 Views
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.
0
Comment
Question by:freshnet
  • 4
  • 3
8 Comments
 
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

0
 
LVL 60

Expert Comment

by:chapmandew
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"...so this would only apply to an NC primary key
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24858857
rrjegan, your example really isn't applicable....by default the primary key is clustered unless you specify otherwise.
0
 
LVL 57

Accepted Solution

by:
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.

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 60

Expert Comment

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

Author Closing Comment

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

Expert Comment

by:chapmandew
ID: 24859653
pretty sure a split would have been necessary here....
0
 
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.

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now