Solved

SQL primary key add INCLUDE column

Posted on 2009-07-15
8
306 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

777 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