![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
How can I drop all indexes from a table, if I do not know exactly which indexes exist? Can I use the sysindexes to generate a stored procedure or something like that? |
#3
| |||
| |||
|
|
Jan van Veldhuizen wrote: How can I drop all indexes from a table, if I do not know exactly which indexes exist? Can I use the sysindexes to generate a stored procedure or something like that? You can certainly create a stored procedure to drop indexes. However, a generic procedure seems not possible as - AFAIK - you can't use variables to specify the table owner. We have - for a similar purpose - created a tool which runs as a Windows executable & lets you use internal variables i.e. to specify the owner of a table. This would be a valid script for our tool: create table TEST (ID INTEGER); create index TEST_IND on TEST(ID); select * from dbo.sysindexes; %% read the name of the index into a local variable select INAME from sys.sysindexes where tname = 'TEST'; %% use local variable to specify the index name drop index $INAME; Klaus -- Die email Adresse (reply-to) im header ist ungueltig. Fuer mail "pub . kp2 . pieper @ ibeq . com" benutzen. (Leerzeichen loeschen). Reply-to invalid. Use "pub . kp2 . pieper @ ibeq . com" (remove spaces). |
#4
| |||
| |||
|
|
Thx. Meanwhile I found a solution: select 'drop index ' + iname + ';' from sysindexes where tname = 'temptable'; output to 'c:\dropall.sql' quote ''; read c:\dropall.sql go commit work go "Klaus P. Pieper" <pub.kp2.pieper (AT) ibeq (DOT) com> wrote in message news:3fd47dd1$1 (AT) forums-2-dub (DOT) .. Jan van Veldhuizen wrote: How can I drop all indexes from a table, if I do not know exactly which indexes exist? Can I use the sysindexes to generate a stored procedure or something like that? You can certainly create a stored procedure to drop indexes. However, a generic procedure seems not possible as - AFAIK - you can't use variables to specify the table owner. We have - for a similar purpose - created a tool which runs as a Windows executable & lets you use internal variables i.e. to specify the owner of a table. This would be a valid script for our tool: create table TEST (ID INTEGER); create index TEST_IND on TEST(ID); select * from dbo.sysindexes; %% read the name of the index into a local variable select INAME from sys.sysindexes where tname = 'TEST'; %% use local variable to specify the index name drop index $INAME; Klaus -- Die email Adresse (reply-to) im header ist ungueltig. Fuer mail "pub . kp2 . pieper @ ibeq . com" benutzen. (Leerzeichen loeschen). Reply-to invalid. Use "pub . kp2 . pieper @ ibeq . com" (remove spaces). |
![]() |
| Thread Tools | |
| Display Modes | |
| |