Re: Constraint problem
Date: 2000/05/24
Message-ID: <392BDCBF.11ADCE67_at_ii.uib.no>#1/1
Philip Lijnzaad wrote:
> Anyway, in UML, this would look like:
>
> +-------------+ +---------------+
> | Complex | | Reference |
> |-------------|-----------|---------------|
> | | + + | |
> | | | |
> +-------------+ +---------------+
>
> In this case, Complex <-> Reference is a many-to-many association for which
> you need to have additional link table; see your text books.
>
> Svenn> So how would I make sure that for every complex has a reference and
> Svenn> every reference refers to a complex?
>
> Make sure the link table has the appropriate foreign keys to Complex and
> Reference.
>
I have now added the following constraints
alter table c_ref
add constraint cr_cacc#_fk
foreign key (cacc#)
references complex (pcacc#);
alter table c_ref
add constraint cr_ref#_fk
foreign key (ref#)
references reference (ref#);
Now I can't insert cacc# values into c_ref whitout inserting them into complex
first.
But with only these constraints nothing
is stopping me to insert values into table complex without inserting any
in table reference. Maybe this isn't possible or dosn't make sence in sql? Or is it
the
developer of the application which uses the database who is responsible for
making sure that the user inserts a reference if he/she is inserting a
complex. (f.ex. in a web form where you have to fill in all the details
before it is sent to the database.)
Regards
Svenn. Received on Wed May 24 2000 - 00:00:00 CEST