Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avoiding selection primary key in sysindexes
Message
 
 
À
04/03/2008 23:08:32
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01298781
Message ID:
01298830
Vues:
18
This message has been marked as the solution to the initial question of the thread.
Try
SELECT name FROM sysindexes
WHERE id = OBJECT_ID(N'MyTable') AND
   indid > 0 AND indid < 255 AND
  INDEXPROPERTY(id, name, 'IsStatistics') = 0
  AND name <> (SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
	WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'
		AND TABLE_NAME = 'MyTable')
>I have this script which removes all indexes from a table. However, as primary keys should be handled differently, I need to adjust this script so it will not grab a primary key. Is that possible?
>
>
>DECLARE tableIndexes CURSOR FOR
>SELECT name FROM sysindexes
>WHERE id = OBJECT_ID(N'MyTable') AND
>   indid > 0 AND indid < 255 AND
>  INDEXPROPERTY(id, name, 'IsStatistics') = 0
>ORDER BY indid DESC
>
>OPEN tableIndexes
>FETCH NEXT FROM tableIndexes INTO @indexName
>WHILE @@fetch_status = 0
>BEGIN
>  SET @dropIndexSql = N'DROP INDEX MyTable.' + @indexName
>  EXEC sp_executesql @dropIndexSql
>  FETCH NEXT FROM tableIndexes INTO @indexName
>END
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform