MySQL Forums
Forum List  »  InnoDB

Re: Possible constraint creation
Posted by: Peter Brawley
Date: November 20, 2015 12:20PM

Quote

Add a constraint between tables that would prevent a record from being deleted from table1 if it exists in table2, but table2 does not have to have an entry from table1.

That's the definition of a foreign key ...

create table a( aid int primary key );
create table b( bid int primary key, aid int, foreign key(aid) references a(aid) );

a.aid values need not exist in b, b.aid values must exist in a.

See the manual page for foreign keys.

Options: ReplyQuote


Subject
Views
Written By
Posted
1478
November 20, 2015 11:56AM
Re: Possible constraint creation
688
November 20, 2015 12:20PM
798
November 23, 2015 06:20AM
757
November 23, 2015 01:00PM
744
November 23, 2015 07:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.