I am writing a script that takes a database and will make all new indexes.
I have about 150 identical databases but they all have slightly different
indexes due to usage, profiler and tuning wizard set them all up separately.
So I want to start from scratch. Is there a statement I can use to drop all
of them at once, preferably also cropping the primary key and clustered
index? Otherwise I will have to look at the system tables, loop over the
user indexes, then drop them one at a time. If a public example script is
available that does that, I'd like to see it as well.
thanks,
CoryCory
SELECT
'DROP INDEX ' +
QUOTENAME(USER_NAME(o.uid)) +
'.' +
QUOTENAME(o.name) +
'.' +
QUOTENAME(i.name)
FROM sysobjects o
JOIN sysindexes i ON
i.id = o.id
WHERE i.indid BETWEEN 1 AND 254 AND
INDEXPROPERTY(i.id, i.name, 'IsStatistics') = 0 AND
INDEXPROPERTY(i.id, i.name, 'IsHypothetical') = 0 AND
NOT EXISTS
(
SELECT *
FROM sysobjects po
WHERE
po.parent_obj = o.id AND
po.name = i.name
) AND
OBJECTPROPERTY(o.id, 'IsMSShipped') = 0
"Cory Harrison" <charrison@.csiweb.com> wrote in message
news:uAN%23vg8LFHA.1156@.TK2MSFTNGP09.phx.gbl...
> I am writing a script that takes a database and will make all new indexes.
> I have about 150 identical databases but they all have slightly different
> indexes due to usage, profiler and tuning wizard set them all up
separately.
> So I want to start from scratch. Is there a statement I can use to drop
all
> of them at once, preferably also cropping the primary key and clustered
> index? Otherwise I will have to look at the system tables, loop over the
> user indexes, then drop them one at a time. If a public example script is
> available that does that, I'd like to see it as well.
>
> thanks,
> Cory
>
>|||Thank you, that works great. Now I just need to figure out what to do with
these clustered indexes...
thanks,
Cory
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:eq0kYYEMFHA.3420@.tk2msftngp13.phx.gbl...
> Cory
> SELECT
> 'DROP INDEX ' +
> QUOTENAME(USER_NAME(o.uid)) +
> '.' +
> QUOTENAME(o.name) +
> '.' +
> QUOTENAME(i.name)
> FROM sysobjects o
> JOIN sysindexes i ON
> i.id = o.id
> WHERE i.indid BETWEEN 1 AND 254 AND
> INDEXPROPERTY(i.id, i.name, 'IsStatistics') = 0 AND
> INDEXPROPERTY(i.id, i.name, 'IsHypothetical') = 0 AND
> NOT EXISTS
> (
> SELECT *
> FROM sysobjects po
> WHERE
> po.parent_obj = o.id AND
> po.name = i.name
> ) AND
> OBJECTPROPERTY(o.id, 'IsMSShipped') = 0
>
> "Cory Harrison" <charrison@.csiweb.com> wrote in message
> news:uAN%23vg8LFHA.1156@.TK2MSFTNGP09.phx.gbl...
> separately.
> all
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment