Board index » delphi » name of interbase primary keys

name of interbase primary keys

Hi friends,
I have noticed that primary keys in interbase have this name:
RDB$PRIMARYNN, where NN is a number. I have also noticed
that this number depends on the order of creation of the tables.
I need a name for the primary key that does not depend on this,
so I can use it in my programs. Can anybody help me with this?
Thanks a lot for any help.
Jaime Escobal
 

Re:name of interbase primary keys


You can name primary keys (and other constraints) by supplying a name for
it. Download the IB6 beta documentation set at
http://www.borland.com/techpubs/interbase/ and check the Language Reference
for the exact syntax.

Btw, InterBase Workbench (http://www.interbaseworkbench.com) automatically
creates primary keys name PK_table (you can edit the name too).

--
Martijn Tonies
InterBase Workbench - the developer tool for InterBase and Firebird
http://www.interbaseworkbench.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."

Quote
"Jaime Escobal" <jaime.esco...@laviga.com> wrote in message

news:3B8D0E14.B3492B81@laviga.com...
Quote
> Hi friends,
> I have noticed that primary keys in interbase have this name:
> RDB$PRIMARYNN, where NN is a number. I have also noticed
> that this number depends on the order of creation of the tables.
> I need a name for the primary key that does not depend on this,
> so I can use it in my programs. Can anybody help me with this?
> Thanks a lot for any help.
> Jaime Escobal

Re:name of interbase primary keys


Quote
In article <3B8D0E14.B3492...@laviga.com>, Jaime Escobal wrote:
> have noticed that primary keys in interbase have this name:
> RDB$PRIMARYNN, where NN is a number. I have also noticed
> that this number depends on the order of creation of the tables.
> I need a name for the primary key that does not depend on this,
> so I can use it in my programs. Can anybody help me with this?
> Thanks a lot for any help.

Don't create a primary key, create the table and add a unique index on
the primary key field using 'create index'. The results will be the
same but you get to name the index.

Robert Schieck (TeamB)
MER Systems Inc.
Inprise/Borland/InterBase Search Engine
http://www.mers.com/searchsite.html

Re:name of interbase primary keys


Thanks for your advice Martijn,  but I cannot seem to find the info on the
manual, or I do not understand it well? could you help me with this?
thanks a lot
jaime
Quote
Martijn Tonies wrote:
> You can name primary keys (and other constraints) by supplying a name for
> it. Download the IB6 beta documentation set at
> http://www.borland.com/techpubs/interbase/ and check the Language Reference
> for the exact syntax.

> Btw, InterBase Workbench (http://www.interbaseworkbench.com) automatically
> creates primary keys name PK_table (you can edit the name too).

> --
> Martijn Tonies
> InterBase Workbench - the developer tool for InterBase and Firebird
> http://www.interbaseworkbench.com

> Upscene Productions
> http://www.upscene.com

> "This is an object-oriented system.
> If we change anything, the users object."

> "Jaime Escobal" <jaime.esco...@laviga.com> wrote in message
> news:3B8D0E14.B3492B81@laviga.com...
> > Hi friends,
> > I have noticed that primary keys in interbase have this name:
> > RDB$PRIMARYNN, where NN is a number. I have also noticed
> > that this number depends on the order of creation of the tables.
> > I need a name for the primary key that does not depend on this,
> > so I can use it in my programs. Can anybody help me with this?
> > Thanks a lot for any help.
> > Jaime Escobal

Re:name of interbase primary keys


Hi Robert,
I did this but I have problems with the FOREIGN KEY references to the
original PRIMARY KEYS. Is there anything besides this I should consider?
Thanks a lot,
Jaime
Quote
Robert Schieck wrote:
> In article <3B8D0E14.B3492...@laviga.com>, Jaime Escobal wrote:
> > have noticed that primary keys in interbase have this name:
> > RDB$PRIMARYNN, where NN is a number. I have also noticed
> > that this number depends on the order of creation of the tables.
> > I need a name for the primary key that does not depend on this,
> > so I can use it in my programs. Can anybody help me with this?
> > Thanks a lot for any help.

> Don't create a primary key, create the table and add a unique index on
> the primary key field using 'create index'. The results will be the
> same but you get to name the index.

> Robert Schieck (TeamB)
> MER Systems Inc.
> Inprise/Borland/InterBase Search Engine
> http://www.mers.com/searchsite.html

Re:name of interbase primary keys


You can name the FK constraint but not the index used to check the
constraint. To relate a table via FK, target table must have a PK
constraint, then is if you create an unique index, that index isn't related
to the constraint then you can't create the FK. You must decide if you can
oive with the system named constraint index created by PK, FK or UNIQUE
constraints and let the server to do the referential check, or use your own
named index but check referential check from client side or using triggers
(that is the way Robert does I think). There is a hack to use user named
index but it appears that is lost with backup/restore. I dislike the name IB
gives to RI constraints but I preffer that than do RI checking manually.

--
Sergio Samayoa
Lgica Software
http://www.geocities.com/logicasw/

"Jaime Escobal" <jaime.esco...@laviga.com> escribi en el mensaje
news:3B8D6C13.48E02F4B@laviga.com...

Quote
> Thanks for your advice Martijn,  but I cannot seem to find the info on the
> manual, or I do not understand it well? could you help me with this?
> thanks a lot
> jaime

> Martijn Tonies wrote:

> > You can name primary keys (and other constraints) by supplying a name
for
> > it. Download the IB6 beta documentation set at
> > http://www.borland.com/techpubs/interbase/ and check the Language
Reference
> > for the exact syntax.

> > Btw, InterBase Workbench (http://www.interbaseworkbench.com)
automatically
> > creates primary keys name PK_table (you can edit the name too).

> > --
> > Martijn Tonies
> > InterBase Workbench - the developer tool for InterBase and Firebird
> > http://www.interbaseworkbench.com

> > Upscene Productions
> > http://www.upscene.com

> > "This is an object-oriented system.
> > If we change anything, the users object."

> > "Jaime Escobal" <jaime.esco...@laviga.com> wrote in message
> > news:3B8D0E14.B3492B81@laviga.com...
> > > Hi friends,
> > > I have noticed that primary keys in interbase have this name:
> > > RDB$PRIMARYNN, where NN is a number. I have also noticed
> > > that this number depends on the order of creation of the tables.
> > > I need a name for the primary key that does not depend on this,
> > > so I can use it in my programs. Can anybody help me with this?
> > > Thanks a lot for any help.
> > > Jaime Escobal

Re:name of interbase primary keys


Quote
Jaime Escobal wrote:
> I need a name for the primary key that does not depend on this,
> so I can use it in my programs. Can anybody help me with this?

e.g.,
(1)
CREATE TABLE Invoice (
   Invoice_No VARCHAR(20) NOT NULL,
   CONSTRAINT XPKInvoice PRIMARY KEY (Invoice_No)
);

(2)
CREATE TABLE Invoice (
   Invoice_No VARCHAR(20) NOT NULL
);

ALTER TABLE Invoice
   ADD CONSTRAINT XPKInvoice PRIMARY KEY (Invoice_No);

Ronald

Re:name of interbase primary keys


He is talking about the index name that is created to enforce the constraint
not the constraint name.

--
Sergio Samayoa
Lgica Software
http://www.geocities.com/logicasw/

"Ronald Mak" <ron...@apsnet.com.hk> escribi en el mensaje
news:3B8DEE67.1080704@apsnet.com.hk...

Quote
> Jaime Escobal wrote:

> > I need a name for the primary key that does not depend on this,
> > so I can use it in my programs. Can anybody help me with this?

> e.g.,
> (1)
> CREATE TABLE Invoice (
>    Invoice_No VARCHAR(20) NOT NULL,
>    CONSTRAINT XPKInvoice PRIMARY KEY (Invoice_No)
> );

> (2)
> CREATE TABLE Invoice (
>    Invoice_No VARCHAR(20) NOT NULL
> );

> ALTER TABLE Invoice
>    ADD CONSTRAINT XPKInvoice PRIMARY KEY (Invoice_No);

> Ronald

Re:name of interbase primary keys


Hi friends,
Following your advice, I created the table with the primary key AND a unique key
with the same columns of the primary key. That way, I thought, I could have both
the primary keys and a key with a name I new beforehand. and I could also have
the foreign keys. but IB does not allow me to declare the foreing keys under
this scenario (strange).. If I delete the foreign key clause,  IBt creates the
table.... So for now I am not using foreign keys, but I would like to have them.

anyway, thanks for your help

Jaime Escobal
jaime.esco...@laviga.com

Quote
Sergio Samayoa wrote:
> You can name the FK constraint but not the index used to check the
> constraint. To relate a table via FK, target table must have a PK
> constraint, then is if you create an unique index, that index isn't related
> to the constraint then you can't create the FK. You must decide if you can
> oive with the system named constraint index created by PK, FK or UNIQUE
> constraints and let the server to do the referential check, or use your own
> named index but check referential check from client side or using triggers
> (that is the way Robert does I think). There is a hack to use user named
> index but it appears that is lost with backup/restore. I dislike the name IB
> gives to RI constraints but I preffer that than do RI checking manually.

> --
> Sergio Samayoa
> Lgica Software
> http://www.geocities.com/logicasw/

> "Jaime Escobal" <jaime.esco...@laviga.com> escribi en el mensaje
> news:3B8D6C13.48E02F4B@laviga.com...
> > Thanks for your advice Martijn,  but I cannot seem to find the info on the
> > manual, or I do not understand it well? could you help me with this?
> > thanks a lot
> > jaime

> > Martijn Tonies wrote:

> > > You can name primary keys (and other constraints) by supplying a name
> for
> > > it. Download the IB6 beta documentation set at
> > > http://www.borland.com/techpubs/interbase/ and check the Language
> Reference
> > > for the exact syntax.

> > > Btw, InterBase Workbench (http://www.interbaseworkbench.com)
> automatically
> > > creates primary keys name PK_table (you can edit the name too).

> > > --
> > > Martijn Tonies
> > > InterBase Workbench - the developer tool for InterBase and Firebird
> > > http://www.interbaseworkbench.com

> > > Upscene Productions
> > > http://www.upscene.com

> > > "This is an object-oriented system.
> > > If we change anything, the users object."

> > > "Jaime Escobal" <jaime.esco...@laviga.com> wrote in message
> > > news:3B8D0E14.B3492B81@laviga.com...
> > > > Hi friends,
> > > > I have noticed that primary keys in interbase have this name:
> > > > RDB$PRIMARYNN, where NN is a number. I have also noticed
> > > > that this number depends on the order of creation of the tables.
> > > > I need a name for the primary key that does not depend on this,
> > > > so I can use it in my programs. Can anybody help me with this?
> > > > Thanks a lot for any help.
> > > > Jaime Escobal

Other Threads