Maybe this is obvious, but I post it anyway, just to remind myself should I need it again.
Recently I had to change a table that I had not completely thought through when I first created it. The structure was so simple, I did not think I could do anything wrong with it:
CREATE TABLE `parent` ( `par_id` bigint(20) NOT NULL, `somevalue` varchar(20) default NULL, PRIMARY KEY (`par_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `child` ( `x_parid` bigint(20) default NULL, `value` bigint(10) default NULL, KEY `fk_parid` (`x_parid`), CONSTRAINT `child_ibfk_1` FOREIGN KEY (`x_parid`) REFERENCES `parent` (`par_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
There is a 1:0..* relationship between parent and child. Some sample data:
mysql> select * from parent; +--------+--------------+ | par_id | somevalue | +--------+--------------+ | 1 | Parent No. 1 | | 2 | Parent No. 2 | | 3 | Parent …[Read more]