Solved

SQL primary key add INCLUDE column

Posted on 2009-07-15
8
327 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
[X]
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
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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