MySQL Forums
Forum List  »  Newbie

Re: How to refresh contents of a child table...
Posted by: Peter Brawley
Date: November 02, 2018 10:43AM

Names change and these are long so they're not ideal keys. Surrogate keys would be preferable.

drop table if exists movies,actors,titles;
create table titles ( 
  tid smallint unsigned primary key auto_increment,
  title varchar(128), 
  genre varchar(32) not null  
); 

create table actors( 
  aid smallint unsigned primary key auto_increment,
  name varchar(128) 
);

create table movies ( 
  mid smallint unsigned primary key auto_increment,
  tid smallint unsigned, 
  aid smallint unsigned, 
  genre varchar(15) references titles(genre), 
  foreign key(tid) references titles(tid) on update cascade on delete cascade,
  foreign key(aid) references actors(aid) on update cascade on delete cascade
  
);

Genre probably should lookup into a table as a FK.

Options: ReplyQuote


Subject
Written By
Posted
Re: How to refresh contents of a child table...
November 02, 2018 10:43AM


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.