MySQL Forums
Forum List  »  Newbie

Re: Relating Tables if Auto Increment Interger is Primary Key
Posted by: Peter Brawley
Date: October 01, 2014 08:22PM

> PK and the FK must be the same

Not quite. FK must exactly type-match the PK it references. For example ...

drop table if exists b,a;
create table a(
  aid int unsigned primary key auto_increment 
);
create table b(
  bid int unsigned primary key auto_increment, 
  aid int unsigned,
  foreign key(aid) references a(aid) on delete cascade on update cascade
);

Options: ReplyQuote


Subject
Written By
Posted
Re: Relating Tables if Auto Increment Interger is Primary Key
October 01, 2014 08:22PM


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.