Converting A Clustered Index On A PK Identity Field To Non-clustered
Sep 8, 2006
Hi there, I have a table that has an IDENTITY column and it is the PK of this table. By default SQL Server creates a unique clustered index on the PK, but this isn't what I wanted. I want to make a regular unique index on the column so I can make a clustered index on a different column.
If I try to uncheck the Clustered index option in EM I get a dialog that says "Cannot convert a clustered index to a nonclustered index using the DROP_EXISTING option.". If I simply try to delete the index I get the following "An explicit DROP INDEX is not allowed on index 'index name'. It is being used for PRIMARY KEY constraint enforcement.
So do I have to drop the PK constraint now? How does that affect all the tables that have FK relationships to this table?
Thanks
View 3 Replies
ADVERTISEMENT
Nov 14, 2006
the query:
SELECT a.AssetGuid, a.Name, a.LocationGuid
FROM Asset a WHERE a.AssociationGuid IN (
SELECT ada.DataAssociationGuid FROM AssociationDataAssociation ada
WHERE ada.AssociationGuid = '568B40AD-5133-4237-9F3C-F8EA9D472662')
takes 30-60 seconds to run on my machine, due to a clustered index scan on our an index on asset [about half a million rows]. For this particular association less than 50 rows are returned.
expanding the inner select into a list of guids the query runs instantly:
SELECT a.AssetGuid, a.Name, a.LocationGuid
FROM Asset a WHERE a.AssociationGuid IN (
'0F9C1654-9FAC-45FC-9997-5EBDAD21A4B4',
'52C616C0-C4C5-45F4-B691-7FA83462CA34',
'C95A6669-D6D1-460A-BC2F-C0F6756A234D')
It runs instantly because of doing a clustered index seek [on the same index as the previous query] instead of a scan. The index in question IX_Asset_AssociationGuid is a nonclustered index on Asset.AssociationGuid.
The tables involved:
Asset, represents an asset. Primary key is AssetGuid, there is an index/FK on Asset.AssociationGuid. The asset table has 28 columns or so...
Association, kind of like a place, associations exist in a tree where one association can contain any number of child associations. Each association has a ParentAssociationGuid pointing to its parent. Only leaf associations contain assets.
AssociationDataAssociation, a table consisting of two columns, AssociationGuid, DataAssociationGuid. This is a table used to quickly find leaf associations [DataAssociationGuid] beneath a particular association [AssociationGuid]. In the above case the inner select () returns 3 rows.
I'd include .sqlplan files or screenshots, but I don't see a way to attach them.
I understand I can specify to use the index manually [and this also runs instantly], but for such a simple query it is peculiar it is necesscary. This is the query with the index specified manually:
SELECT a.AssetGuid, a.Name, a.LocationGuid
FROM Asset a WITH (INDEX (IX_Asset_AssociationGuid)) WHERE
a.AssociationGuid IN (
SELECT ada.DataAssociationGuid FROM AssociationDataAssociation ada
WHERE ada.AssociationGuid = '568B40AD-5133-4237-9F3C-F8EA9D472662')
To repeat/clarify my question, why might this not be doing a clustered index seek with the first query?
View 15 Replies
View Related
Sep 4, 2015
We are going to use SQL Sever change tracking. The problem is that some of our tables, which are to be tracked, have no primary keys. There are only unique clustered indexes. The question is what is the best way to turn on change tracking for these tables in our circumstances.
View 4 Replies
View Related
Aug 28, 2015
I desire to have a clustered index on a column other than the Primary Key. I have a few junction tables that I may want to alter, create table, or ...
I have practiced with an example table that is not really a junction table. It is just a table I decided to use for practice. When I execute the script, it seems to do everything I expect. For instance, there are not any constraints but there are indexes. The PK is the correct column.
CREATE TABLE [dbo].[tblNotificationMgr](
[NotificationMgrKey] [int] IDENTITY(1,1) NOT NULL,
[ContactKey] [int] NOT NULL,
[EventTypeEnum] [tinyint] NOT NULL,
[code]....
View 20 Replies
View Related
Jul 19, 2013
I have created two tables. table one has the following fields,
Id -> unique clustered index.
table two has the following fields,
Tid -> unique clustered index
Id -> foreign key of table one(id).
Now I have created primary key for the table one column 'id'. It's created as "nonclustered, unique, primary key located on PRIMARY". Primary key create clustered index default. since unique clustered index existed in table one, it has created "Nonclustered primary key".
My Question is, What is the difference between "clustered, unique, primary key" and "nonclustered, unique, primary key"? Is there any performance impact between these?
View 5 Replies
View Related
Jan 4, 2008
I have large table with 10million records. I would like to create clustered or non-clustered index.
What is the quick way to create? I have tried once and it took more than 10 min.
please help.
View 1 Replies
View Related
Aug 2, 2015
I am extremely new to database design, and I ran into a problem that I know comes up often, however has many opinions...
Basically I have a table that is going to have 50+ columns. The natural key on this table is actually 8 columns wide, 4 of them being Varchar columns by default. (varchar(50)'s).
I have added an identity column, (1,1) to the table, however I put the clustered index on the 8 natural keys... My plan is to rebuild the clustered index once nightly when the system isn't in use (after 7 pm).
I know others would say it would be better to have the clustered key on the 1,1 column and then add indexes on the other 8 fields... However I don't quite understand why honestly...
Every single query against this table will use the 8 columns, and will NOT use the Identity column (1,1) because they are calls from other systems that do not know the Identity column....
Therefore if your database is set up for query speed, and every single query has to have a value for 8 columns to get a valid result, does it make sense to put a clustered index over the 8 columns?
If not why? Why is putting a clustered index on an identity column (that will literally never be used in a query) a better solution?
View 9 Replies
View Related
Nov 1, 2007
I have a table<table1> with 804668 records primary on table1(col1,col2,col3,col4)
Have created non-clustered index on <table1>(col2,col3,col4),to solve a performance issue.(which is a join involving another table with 1.2 million records).Seems to be working great.
I want to know whether this will slow down,insert and update on the <table1>?
View 2 Replies
View Related
Jul 23, 2005
Would it be OK to use varchar(5) instead of char(5) as the first field of acomposite clustered index?My gut tells me that varchar would be a bad idea, but I am not finding muchinformation on this topic on this when I Google it.Currently the field is Char(4), and there is a need to increase it to hold 5characters.TIA
View 2 Replies
View Related
Oct 15, 2007
Hi everybody!
I just ran the Database Engine Tuning Advisor on a relative complex query to find out if a new index might help, and in fact it found a combination that should give a performance gain of 94%. Fair enough to try that.
What I wonder about: The index I should create contains 4 columns, the last of them being the Primary Key column of the table, which is also my clustered index for the table. It is an identity integer btw.
I think I remember that ANY index does include the clustered one as lookup into the data, so having it listed to the list of columns will not help. It might at worst add another duplicate 4 bytes to each index entry.
Right? Wrong? Keep the column in the index, or remove it since it is included implicit anyway?
Thanks for suggestions!
Ralf
View 3 Replies
View Related
Dec 6, 2005
What does an index add to the performance?
Why do we use Clustered Index and Non-clustered Index?
thanks
View 3 Replies
View Related
Jan 3, 2008
Does creating both a Clustered and Non-Clustered on the same field increase performace or decrease performance?
Or having either one is enough?
View 1 Replies
View Related
Aug 24, 2006
Hello,
How do I restore a sql database that is on a clustered server from a sql database backup file that is on a non_clustered server?
Thanks,
Serey
View 3 Replies
View Related
Nov 24, 2014
What is the easiest way to remember the definitions of clustered and non clustered indexes.
View 9 Replies
View Related
Sep 30, 2015
I have a really super slow stored proc that does something simple. it updates a table if certain values are received.
In looking at this the matching is done on the Primary Key, which is set as a Clustered index, looking further I have another constraint, that sets the same column to a Unique, Non-Clustered.
I am not sure why this was done, but it seems to be counter productive. I have read only references to Which one is better on a primary key, but not can their be both and if it is "Smart".
View 4 Replies
View Related
Dec 5, 2007
Dear All.
We had Teradata 4700 SMP. We have moved data from TD to MS_SQL SERVER 2003. records are 19.65 Millions.
table is >> Order_Dtl
Columns are:-
Client_ID varchar 10
Order_ID varchar 50
Order_Sub_ID decimal
.....
...
..
.
Pk is (ClientID+OrderId+OrderSubID)
Web Base application or PDA devices use to initiate the order from all over the country. The issue is this table is not Partioned but good HP with 30 GB RAM is installed. this is main table that receive 18,0000 hits or more. All brokers and users are using this table to see the status of their order.
The always search by OrderID, or ClientID or order_SubNo, or enter any two like (Client_ID+Order_Sub_ID) or any combination.
Query takes to much time when ever server receive more querys. some orther indexes are also created on the same table like (OrderDate, OrdCreate Date and Status)
My Question are:-
Q1. IF Person "A" query to DB on Client_ID, then what Index will use ? (If any one do Query on any two combination like Client_ID+Order_ID, So what index will be uesd.? How does MS-SQL SERVER deal with these kind of issues.?
Q2. If i create 3 more indexes on ClientID, ORderID and OrdersubID. will this improve the performance of query.if person "A" search record on orderNo so what index will be used. (Mind it their would be 3 seprate indexes for Each PK columns) and composite-Clustered index is also available.?
Q3. I want to check what indexes has been used? on what search?
Q4. How can i check what table was populated when, or last date of update (DML)?
My Limitation is i Dont Create a Partioned table. I dont have permission to do it.
In Teradata we had more than 4 tb record of CRM data with no issue. i am not new baby in db line but not expert in sql server 2003.
I am thank u to all who read or reply.
Arshad
Manager Database
Esoulconsultancy.com
(Teradata Master)
10g OCP
View 3 Replies
View Related
Jul 3, 2006
Hi everyone,
When we create a clustered index firstly, and then is it advantageous to create another index which is nonclustered ??
In my opinion, yes it is. Because, since we use clustered index first, our rows are sorted and so while using nonclustered index on this data file, finding adress of the record on this sorted data is really easier than finding adress of the record on unsorted data, is not it ??
Thanks
View 4 Replies
View Related
Feb 26, 2008
Hello,
I've a table with primary key defined as non-clusterd, now without dropping it can I modify the existing index to clustered through tsql as I had to write some migration script and in that script I wanna do this.
Thanks in Advance,
Rohit
View 5 Replies
View Related
May 22, 2000
Hi,
I have a small table (around 10,000 rows) that is constantly selected from, deleted from, and inserted into. Basically we fill it with content, our web application selects the content, and when we run out, we regenerate (about 50 rows at a time). We currently have a nonclustered PK on the first two columns, both INTs. How can I determine if a clustered index would be better? I am concerned about bottlenecks due to a hotspot with the nonclustered index. When our site really starts to get users, this could become a big issue. I am thinking that I could use a clustered index, and set up a job to reindex the table once every hour or so....any help is appreciated greatly.
View 3 Replies
View Related
Dec 9, 2000
Does anybody know if a key defined on Uniqueidentifier datatype is a good candidate for the clustered index or otherwise.
View 1 Replies
View Related
Jun 29, 2007
Hi,
Is it advisable to create a Non Clustered Index in "ALLow NULL" column?
Thanks,
Rahul Jha
View 4 Replies
View Related
Nov 11, 2012
In Microsoft SQL Management Studio 2005 I have the ability to add a single non clustered index on a table on multiple columns (ordered how I want) AND/OR I may create a multiple of these non-clustered Index entries with a single column per non-clustered index.
Is there a difference between to two options? If yes, how do these options work differently? I assume option 1 is just a faster way of creating the non-clustered index and there is no architectural difference!?
View 2 Replies
View Related
Apr 13, 2008
Why can we have only one clustered index per table
View 4 Replies
View Related
Oct 20, 2014
what is clustered index A and B.
View 4 Replies
View Related
Jan 14, 2007
Hi,
I have a table which I would like to index.
The table holds info of nurses:
T_NURSE=(NurseCode, LName, FName, IDNumber ...)
NurseCode => PK+Identity
Since queries will be on LName (and optionally on FName and IDNumber) I created a clustered index with this order: {LName, FName, IDNumber, NurseCode}
Questions:
1.Is it ok to have the clustered index not the PK?
2.If yes - what importance does the PK have here?
Looking for a nurse via screen (using:LName,FName,ID) or via source-code (using:NurseCode) is 50%/50%.
Which field(s) should have the honor of being a PK?
3.If I perform the search using a view (SELECT * FROM vw_Nurse) will it use the index?
Thanks,
Izik
View 11 Replies
View Related
Jul 17, 2006
A lot of detailed discussion explains the difference between clusteredand non-clustered indexes. But very few 'clarifies' why the term usedis 'clustered'. Well, once and for all, this is my take.*** The 'CLUSTERED' adjective refers to the INDEX being clustered (setadjacent) to the DATA.This means if you found the index, the data is already there beside it(you don't have to look anywhere else). From this note, everythinghopefully becomes clearer to you. (You can now read further in the techbook :-).So, the next time you are asked to explain what is a clustered (ornon-clustered ) index think of the above.
View 1 Replies
View Related
Sep 28, 2006
Hi,
I have a table Student with N number of columns.
One of the column (int) is flgActive - which currently holds only 2 values either 0 / 1.
Depending on the operation I want do - I either include the where clause flgActive = 0 or flgActive = 1 in my queries. Basically I either fetch non-active students or active students.
Whenever I need to turn a student to Nonactive - flgactive column is updated to 0.
Will a non clustered index on flgActive column help in my querying - when all the records in the table is going to contain only 2 different values. (Assume that the student table holds abt 2 Million records with about 30% of the students nonactive.)
Thanks,
Loonysan
View 6 Replies
View Related
Mar 5, 2015
I have a clustered index that consists of 3 int columns in this order: DateKey, LocationKey, ItemKey (there are many other columns in this data warehouse table such as quantities, prices, etc.).
Now I want to add a non-clustered index on just one of the other columns, say LocationKey, like this:
CREATE INDEX IX_test on TableName (LocationKey)
I understand that the clustered index keys will also be added as key columns to any NC indexes. So, in this case the NC index will also get the other two columns from the clustered index added as key columns. But, in what order will they be added?
Will the resulting index keys on this new NC index effectively be:
LocationKey, DateKey, ItemKey
OR
LocationKey, ItemKey, DateKey
Do the clustering keys get added to a NC index in the same order as they are defined in the clustered index?
View 1 Replies
View Related
Jun 18, 2008
Quick question about the primary purpose of Full Text Index vs. Clustered Index.
The Full Text Index has the purpose of being accessible outside of the database so users can query the tables and columns it needs while being linked to other databases and tables within the SQL Server instance.
Is the Full Text Index similar to the global variable in programming where the scope lies outside of the tables and database itself?
I understand the clustered index is created for each table and most likely accessed within the user schema who have access to the database.
Is this correct?
I am kind of confused on why you would use full text index as opposed to clustered index.
Thank you
Goldmember
View 2 Replies
View Related
Aug 20, 2004
I have a clustered index (Group_ID, Member_ID)
How do I set Member_ID to be an autoincrement field ( each should start at 1 for each Group_ID).
Can SQL Server autoincrement feature do this?
If not is the best way then use a stored procedure to get the max member_ID for that Group, increment it with 1 and the assign it to the new member_ID?
View 3 Replies
View Related
Feb 6, 2006
does putting clustered index makes records physically ordered and grouped??
View 2 Replies
View Related
Nov 6, 2001
I am a little confused about what fill factor to use in creating a clustered index on one of our major tables.
This table has about 4.5 million rows and currently there are 14 indexes associated with it, but no clustered index.
I want to create a clustered index (on datestamp )on this table, but cannot really grasp what fillfactor I should use.
The main use of this table is in daterange reporting.
No deletes are applied to this table(except archiving on an annual basis).
It grows by about 5 000 rows daily.
From what I have read in BOL, a high fillfactor(100) is only applicable for a read only table, and I feel that at the time of creating a clustered index on this table, it is readonly, cos the data will never need to be reorganised to insert a new row into it, only at end.
BOL states that a low fillfactor could degrade database read performance,
and where the vast majority of our processing(reporting) hits this table,that is a major concern.
BUT BOL also says that a low Fillfactor is recommended where there are changes to the data.
Space is obviously important, but access speed is overwhelmingly more important.
Should I use a fillfactor of 70/80/90 etc. Any help would be appreciated
View 2 Replies
View Related
Aug 15, 2000
How much does a table increase(%)in size when a non clusterd index is added to a column in that table if the table has say 1000 records?
Thanks.
View 1 Replies
View Related