Re: foreign keys and row types?
Posted in 1997
There are also check constraints and default values. Your foreign key
references can be created when you:
1. Create the table i.e.:
Create table some_tbl (
col1 serial not null,
col2 char(10) CHECK (col3 > 0) ,
col3 char(1) DEFAULT "1"
PRIMARY KEY (col1) );
2. When you create an index that actual defines the relationship (RI)
between tables along with altering the table to define the constraint:
Create table some_tbl(
col1 serial not null,
col2 char(10) CHECK (col3 > 0) ,
col3 char(1) DEFAULT "1" ) ;
create unique index pk_some_tbl on some_tbl(col1);
Alter table some_tbl add constraint primary key (col1) constraintsome_tbl_pk;
I prefer the later (#2) so that indexes can be named with some meaning
verses the other (#1) since this would create an Informix default NAMED
index. Also you can drop the constraint and still keep the consistency in
your data, so that you can later apply it if needed. This of course is just
two reason's of using the later, I know other DBAs have maybe more.
You can not create "CHECK" constraints for columns across tables, but you
can use the ALTER TABLE ADD CONSTRAINT statement to create a constraint
that checks values in more then one column.
The only integrity constraint you can define on row type
is the NOT NULL-constraint.
___________________________________________
D. Petkovic
petkovic@fh-rosenheim.de
Al Wang wrote:
>
> Hi,
>
> I was wondering, is it possible to create foreign key references within a
> row type definition, or do you have to make the reference when you
> actually create a table?
>
> Thanks