foreign key w/o foreign/primary key

foreign key w/o foreign/primary key

Post by seanl.. » Wed, 17 Jan 2001 08:47:35



Does anyone have an opinion on the most efficient way to check
referential integrity on a table where the would-be foreign key is
neither unique or primary?  Would I use a check constraint?  If so, how
without a subquery?

Thanks in advance,

Sent via Deja.com
http://www.deja.com/

 
 
 

foreign key w/o foreign/primary key

Post by Ion Mane » Wed, 17 Jan 2001 14:52:07


Quote:> Does anyone have an opinion on the most efficient way to check
> referential integrity on a table where the would-be foreign key is
> neither unique or primary?  Would I use a check constraint?  If so, how
> without a subquery?

How about making your schema relational?

Trying to cover a bad design up with code is a recipe for ... well you
know.

Lots of things will work. But a redesign of something that is obviously
flawed is the best answer.

Daniel A. Morgan

 
 
 

1. Trigger to check a foreign key without using foreign key

Hello,

I want to use a trigger to check a foreign key.

Let's assume :

table LIGNES_V contains field ID_ARTICLE char(25)
table STOCK contains field S_ID char(10)

In table LIGNES_V, ID_ARTICLE must contain '' or a valid value from S_ID in
STOCK
(because of the '' -> could not use a standard foreign key)

In the update trigger of LIGNES_V, i placed

if update(id_article) and exists (select id_article from inserted where
(id_article>' ') and  (left(id_article,10) not in (select s_id from stock)))
 RAISERROR ( 'ID_ARTICLE does not match S_ID !',16,1 )

it works very fine and gives the correct result.

BUT : i assume that this request containing a sub-request will result in bad
performances.

Does somebody have an idea to write this trigger on a more-performing way ?

Thanks for help,

Kind regards,

Guy

2. Editing array of rows in i4gl

3. Informix-4GL wanted

4. Foreign Key as subset of Primary Key

5. Screen - small or large fonts ??

6. Identification of a primary key/foreign key

7. Deleting one backup set from a backup device

8. One FOREIGN KEY refrences a Table with two Primary Keys

9. Copying Primary Key to Foreign Key

10. Changing Primary Key Values when foreign key constraints exist

11. delete primary key records together with the foreign keys records

12. Replication with Primary Keys & Foreign Keys Schema