Subject | Re: How to obtain the primary key column(s) |
---|---|
Author | fabiano_bonin |
Post date | 2003-11-13T12:49:02Z |
Thanks for the 'instant' reply.
Its working 100% now:
select
a.rdb$relation_name,
c.rdb$field_name
from
rdb$relations a
inner join rdb$indices b on b.rdb$relation_name =
a.rdb$relation_name
inner join rdb$index_segments c on c.rdb$index_name =
b.rdb$index_name
inner join rdb$relation_constraints d on d.rdb$index_name =
b.rdb$index_name
where
( d.rdb$constraint_type = 'PRIMARY KEY' )
order by
a.rdb$relation_name, c.rdb$field_position
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
Its working 100% now:
select
a.rdb$relation_name,
c.rdb$field_name
from
rdb$relations a
inner join rdb$indices b on b.rdb$relation_name =
a.rdb$relation_name
inner join rdb$index_segments c on c.rdb$index_name =
b.rdb$index_name
inner join rdb$relation_constraints d on d.rdb$index_name =
b.rdb$index_name
where
( d.rdb$constraint_type = 'PRIMARY KEY' )
order by
a.rdb$relation_name, c.rdb$field_position
--- In firebird-support@yahoogroups.com, "Martijn Tonies"
<m.tonies@u...> wrote:
> Hi,works,
>
> > If i create a table like this:
> >
> > create table table1 (
> > id integer not null primary key,
> > column1 varchar(10) );
> >
> > or like this:
> >
> > create table table2 (
> > id1 integer not null,
> > id2 integer not null,
> > column1 varchar(10) );
> > alter table table2 add primary key (id1, id2);
> >
> > How can i obtain, based on system tables, the columns used in the
> > primary key of both tables? I am using the query below and it
> > but i am worried if the index used by the primary key will alwaysway
> > begin with 'RDB$PRIMARY'. I'd like to know if there is a better
> > to do that.& MS SQL
>
> Also take a look at RDB$RELATION_CONSTRAINTS for constraints
> of type 'PRIMARY KEY' -> use the index name found in that table.
>
>
> With regards,
>
> Martijn Tonies
> Database Workbench - developer tool for InterBase, Firebird, MySQL
> Server.
> Upscene Productions
> http://www.upscene.com