dbTalk Databases Forums  

drop ALL indexes from a table

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss drop ALL indexes from a table in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jan van Veldhuizen
 
Posts: n/a

Default drop ALL indexes from a table - 12-08-2003 , 06:51 AM






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?



Reply With Quote
  #2  
Old   
Klaus P. Pieper
 
Posts: n/a

Default Re: drop ALL indexes from a table - 12-08-2003 , 07:27 AM






Jan van Veldhuizen wrote:
Quote:
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).



Reply With Quote
  #3  
Old   
Jan van Veldhuizen
 
Posts: n/a

Default Re: drop ALL indexes from a table - 12-08-2003 , 07:47 AM



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

Quote:
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).




Reply With Quote
  #4  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: drop ALL indexes from a table - 12-08-2003 , 08:24 AM



Use EXECUTE IMMEDIATE and a cursor loop if you want to avoid the
intermediate file.

Breck

On 8 Dec 2003 05:47:23 -0800, "Jan van Veldhuizen"
<jan (AT) van-veldhuizen (DOT) nl> wrote:

Quote:
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).


--
bcarter (AT) risingroad (DOT) com
Mobile and Distributed Enterprise Database Applications
www.risingroad.com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.