Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Avoiding selection primary key in sysindexes
Message
From
04/03/2008 23:08:32
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Avoiding selection primary key in sysindexes
Miscellaneous
Thread ID:
01298781
Message ID:
01298781
Views:
79
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
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform