August 5, 2004 at 8:08 am
Hi Gurus,
In my production environment a few non clustered PKs are to converted into clustered index (PK), and there are child tables (FKs ) are exists, so i can not drop and recreate this PKs. Can anybody suggest me a way without dropping PK can we convert (rebuild) index from non clustered to clustered ?
TIA,
Sheilesh
August 5, 2004 at 8:25 am
You can convert a non-clustered PK to Clustered PK even though there are chilled tables referencing the parent table. It might take longer time depends on how big is your parent table. You might want to schedule a time to implement in prod
Shas3
August 5, 2004 at 11:10 pm
Hi,
Thanks, I can not drop and re-create as dependent FK are there. The conventional way is drop all the FK's for the PK then drop PK and re-create it as clustered.
It will be great if anybody can suggest a way other then this conventional way (without dropping FKs).
TIA,
Sheilesh
TIA,
Sheilesh
August 6, 2004 at 1:21 am
Ah. I think what you are looking for is:
CREATE CLUSTERED .. INDEX index_name ...... WITH DROP_EXISTING
The index name specified must be the same as a currently existing index. SQL Server then creates the clusertered index without unlinking the foreign keys, and doesn't cause nonclustered keys to be rebuilt! So much faster!
If you've got your tempdb on a separate i/o channel, you can use the SORT_IN_TEMPDB option for added speed.
Julian Kuiters
juliankuiters.id.au
August 6, 2004 at 1:48 am
Thanks Julian, Yes i am searchig for the same. I will get back to u. If i find any problem in using it.
Thanks again,
Cheers,
Sheilesh
August 6, 2004 at 7:06 am
CREATE CLUSTERED INDEX does cause the non-clustered index(es) to be rebuilt.
Refer to the BOL, use the Index tab, enter CREATE INDEX. Choose the option for Transact SQL. Scroll down to the section titled CLUSTERED. Read the 3rd paragraph.
It says.....Existing non-clustered indexes on a table are rebuilt when a clustered index is created.
-SQLBill
BOL=Books OnLine=Microsoft SQL Server's HELP
Installed as part of the Client Tools
Found at Start>Programs>Microsoft SQL Server>Books OnLine
August 6, 2004 at 7:50 am
You don’t need to drop and recreate. Simple check the box “Clustered” it will automatically converts to clustered PK. I did this a while back in EM for a large take. Took long time
Shas3
August 6, 2004 at 8:39 am
Shas3,
The reason it took a long time was that the indexes WERE dropped and recreated. EM does a lot of stuff 'behind the scenes'.
For example, if you want to change the order of the columns in a table, EM lets you just choose the order, but then it creates a new table with the columns in the new order, copies the data from the original table into the new one, drops the original table and then renames the new table. But EM doesn't tell you it's doing that.
EM makes things look easy, but all it really does is do the coding for you so you don't have to figure it out.
-SQLBill
August 6, 2004 at 8:46 am
Thanks Bill. I agree with you
Shas3
August 8, 2004 at 9:48 pm
I think that Sheilesh is trying to convert the non-clustered primary keys to clustered, and that they cannot be dropped because of foreign keys.
Yes, other non-clustered indexes need to be rebuild, because of the way sql server then points these non-clustered index keys to a primary key to a row for faster table access.
Sheilesh didn't mention that speed was the issue here, more that they want to convert to clustered primary keys, without dropping the existing. Assuming also that this is a production server, you want to keep the index "online" as much as possible. With DROP_EXISTING, you are doing two steps (drop,create) in one.
Quote from BOL with added highlights:
Julian Kuiters
juliankuiters.id.au
August 9, 2004 at 12:10 am
Lets assume speed is the issue and the FK-cannot be touched over here and
Sheilesh Paliwal cannot wait until the normal maintenance time.
Maybe creating another index as clustered indes, that matches the PK exact is an option.
- # rows ?
- # inputs, updates, deletes ?
- datavolume ?
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply