Board index » delphi » [BDE4.51][Pdx]Creation of a secundary idx when no Primary key exists

[BDE4.51][Pdx]Creation of a secundary idx when no Primary key exists

Hi,

On some tables, I need a non unique index but don't need primary key.
I can handle handle it with Database Desktop, but by code, no way...
Id there is no existing primary key, no secundary indexes will be
accepted.

ex:

This code works:

 with Tmp_Table do begin
   Exclusive := true;
    Open;
    IndexDefs.Update;
    AddIndex('','Br_Id',[ixPrimary]);
    AddIndex('MyIdx','br_Label',[ixCaseInsensitive]);
    IndexName := 'MyIdx';
  end;

This one does not :

 with Tmp_Table do begin
   Exclusive := true;
    Open;
    IndexDefs.Update;
    // AddIndex('','Br_Id',[ixPrimary]);
    AddIndex('MyIdx','br_Label',[ixCaseInsensitive]);
    IndexName := 'MyIdx';
  end;

If DBD can do it, why can't I do it by code ?
Jerome Bouvattier
jerome.bouvattier@**NOSPAM**abrilog.com

 

Re:[BDE4.51][Pdx]Creation of a secundary idx when no Primary key exists


As far as I know you can't have ANY maintained secondary indexes without the
primary one. Would it bother you that much to set up also a primary index?

--
Florin Vancea (fvancea.ns...@texnet.ro)
(please remove nspam from return mail address)

Re:[BDE4.51][Pdx]Creation of a secundary idx when no Primary key exists


Hi Florin,

thank you for replying.

Quote
>As far as I know you can't have ANY maintained secondary indexes without the
>primary one.

You're right, I didn't noticed that the secundary idx I was creating
in DBD was forced to be non maintained !

Quote
>Would it bother you that much to set up also a primary index?

Yes, sometimes. 2 examples

1) I have a table PRODUCTS.db that contains products informations.
Each of these products may have one or more images that I store in a
second table in a BLOB field. So this second table has two fields
Product_Id (Integer)
Image(BLOB)
In this case, you can't set up a primary Key. Except by adding a new
field that would handle it. From what you just pointed ou before, I
understand that I will be obliged to do that.

2) Sometimes I use dbiMakePermanent to retrieve the result of a Query
in a temp table. In this case, I offer my users the possibility to
sort this temp table on any field by adding an index on it. As this
table is just a temporary one, a primary key is not vital and it takes
time to create it.

By.
Jerome Bouvattier
jerome.bouvattier@**NOSPAM**abrilog.com

Re:[BDE4.51][Pdx]Creation of a secundary idx when no Primary key exists


Quote
>2) Sometimes I use dbiMakePermanent to retrieve the result of a Query
>in a temp table. In this case, I offer my users the possibility to
>sort this temp table on any field by adding an index on it. As this
>table is just a temporary one, a primary key is not vital and it takes
>time to create it.

As I don't need maintained indexes in this case, I just tried to
create by code a non maintained index without an existing primary key.
Did not succeed with AddIndex, but it works well with BDE API calls.

My problem is half solved ! But fully understood !

thank you .

Jerome Bouvattier
jerome.bouvattier@**NOSPAM**abrilog.com

Other Threads