Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Avoiding selection primary key in sysindexes
Message
 
 
To
04/03/2008 23:08:32
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01298781
Message ID:
01298830
Views:
20
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--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform