If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Dropping An Indexed Column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-03, 18:37
URSULASADIQ URSULASADIQ is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Dropping An Indexed Column

I have inherited a table with dozens of columns that I no longer want. I want to drop these columns.

So I tried
"ALTER TABLE mydata DROP BLOCK_ID"

and it get an error of: cannot delete a field that is part of an index. How do I get around this?

(BLOCK_ID is the field name of my indexed column)
(The non-indexed ones drop fine.)
Reply With Quote
  #2 (permalink)  
Old 09-26-03, 00:00
tm_suren tm_suren is offline
Registered User
 
Join Date: Sep 2003
Location: Colombo, Sri Lanka
Posts: 63
First remove the column you want to drop from all the indexes that refer it. If there are indexes that refer only that column just drop those. Then you can drop the column.

Cheers,
Suren.
Reply With Quote
  #3 (permalink)  
Old 09-26-03, 09:35
URSULASADIQ URSULASADIQ is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Yes, I get that I have to drop the index(es) -- but how do I find out which indexes this column is in?

I'm building up to write some scripts to automatically drop a long-list of unwanted columns - how does one go about figuring out what index a field is in? And/or is there a sql way of saying "drop this column and it's indexes" ?
Reply With Quote
  #4 (permalink)  
Old 09-28-03, 23:06
tm_suren tm_suren is offline
Registered User
 
Join Date: Sep 2003
Location: Colombo, Sri Lanka
Posts: 63
Well to do that the mist easiest way is to use a graphical tool that organise indexes unser each table and to go through the index and remove the coloms.

If you are thinking of writing scripts then you should select from catalog tables such as user_indexes and user_inx_cols. I think I got the names correct.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On