Board index » delphi » Removing a primary index

Removing a primary index

I am looking to remove the primary index from a table.   The Delphi help for
the for the TTable.DeleteIndex procedure says that it cannot be used to
remove a primary index.  The question I then have is how would you remove
the primary index?  If you delete the item for the primary index from the
TTable.IndexDefs list will it update the table properly?  Or will the
DeleteIndex procedure work properly if you remove all secondary indexes
first?  I have been told that even within Paradox you cannot remove the
primary index from a table if there are any secondary indexes on the table.
And that you need to remove the secondary indexes first, before the primary
is able to be removed.  Anyone have any suggestions?

Thanks In advance.

 

Re:Removing a primary index


Upon further testing I have found that as long as you delete all of the
secondary indexes, the DeleteIndex function will work for the primary index.

An example is as follows (to remove all indexes on a table):

var
   I : integer;

for I := Table.IndexDefs.Count - 1 downto 0 do
   Table.DeleteIndex(Table.IndexDefs[I].Name);

Quote
"Michael Simons" <michael_sim...@mcsspectrum.com> wrote in message

news:3a8acbe2$1_2@dnews...
Quote
> I am looking to remove the primary index from a table.   The Delphi help
for
> the for the TTable.DeleteIndex procedure says that it cannot be used to
> remove a primary index.  The question I then have is how would you remove
> the primary index?  If you delete the item for the primary index from the
> TTable.IndexDefs list will it update the table properly?  Or will the
> DeleteIndex procedure work properly if you remove all secondary indexes
> first?  I have been told that even within Paradox you cannot remove the
> primary index from a table if there are any secondary indexes on the
table.
> And that you need to remove the secondary indexes first, before the
primary
> is able to be removed.  Anyone have any suggestions?

> Thanks In advance.

Re:Removing a primary index


Michael

There are big dangers in deleting primary indexes and then recreating them.
The only way to legitimately delete a primary index that I can see in the
documentation is with the sql statement eg DROP INDEX DBFILE.PRIMARY however
even when you use this statement the BDE can still AV when recreating the
index.

My scenario was backing up only table files then recreating the indexes
after restoring them.

I can send you a simple project demonstrating the problem if you like.

I pursued this with Borland - the ultimate answer from them was that "you
are not allowed to delete a primary index" which comtradicts the
documentation as quoted above.

Tony Christiansen

Quote
"Michael Simons" <michael_sim...@mcsspectrum.com> wrote in message

news:3a8adda5_2@dnews...
Quote
> Upon further testing I have found that as long as you delete all of the
> secondary indexes, the DeleteIndex function will work for the primary
index.

> An example is as follows (to remove all indexes on a table):

> var
>    I : integer;

> for I := Table.IndexDefs.Count - 1 downto 0 do
>    Table.DeleteIndex(Table.IndexDefs[I].Name);

> "Michael Simons" <michael_sim...@mcsspectrum.com> wrote in message
> news:3a8acbe2$1_2@dnews...
> > I am looking to remove the primary index from a table.   The Delphi help
> for
> > the for the TTable.DeleteIndex procedure says that it cannot be used to
> > remove a primary index.  The question I then have is how would you
remove
> > the primary index?  If you delete the item for the primary index from
the
> > TTable.IndexDefs list will it update the table properly?  Or will the
> > DeleteIndex procedure work properly if you remove all secondary indexes
> > first?  I have been told that even within Paradox you cannot remove the
> > primary index from a table if there are any secondary indexes on the
> table.
> > And that you need to remove the secondary indexes first, before the
> primary
> > is able to be removed.  Anyone have any suggestions?

> > Thanks In advance.

Re:Removing a primary index


Quote
>I am looking to remove the primary index from a table.

Use SQL Drop Index

DROP INDEX Orders.PRIMARY

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Removing a primary index


"Brian Bushay TeamB" <BBus...@Nmpls.com> wrote in message
news:i9jm8tgtbng8nk0c2cueqtf9v69kp1k9u6@4ax.com...

Quote

> >I am looking to remove the primary index from a table.

> Use SQL Drop Index

> DROP INDEX Orders.PRIMARY

I'm assuming this will remove all of the secondary indexes as well?
Quote
> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:Removing a primary index


Quote
>I'm assuming this will remove all of the secondary indexes as well?

It seems to do that.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Removing a primary index


| Upon further testing I have found that as long as you delete all of the
| secondary indexes, the DeleteIndex function will work for the primary
index.
|
| An example is as follows (to remove all indexes on a table):
|

This removes the primary key and all secondary indexes at the same time.
We have been using this technique for years without problem.

Table.deleteIndex( '' );

Our automated routines use dbiRestructure to recreate indexes. We are
left with a backup file.

In some situations we have to delete index tables using the OS .This can
happen if the primary key is out of date or corrupted.

Garry Kernan

Other Threads