Example:
Table “persons”, Column “surname” may only contain values predefined in
Table “names”, Column “surnames”, which would contain a collection of surnames acceptable for the purpose.
Can I achieve this by design (i.e. without involving any validation code)? On a MyISAM table? No? On InnoDB?
Thank you.
What you’re asking for is a foreign key constraint. You’d need to use InnoDB – quote:
To add a foreign key constraint within the CREATE TABLE statement for
PERSONS:Using an ALTER TABLE statement if the tables already exist:
Be aware that if you use the
ALTER TABLEstatement, the data in thePERSONStable can only contain surname values that exist in theNAMES.surnametable – it can not be applied until after the data has been fixed.