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
Solved

SQL primary key add INCLUDE column

Posted on 2009-07-15
8
312 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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
 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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 I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

837 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