SET foreign_key_checks = 0; CREATE TABLE `A` ( `A_id` int(11) NOT NULL AUTO_INCREMENT, `N_id` int(11) NOT NULL, PRIMARY KEY (`A_id`), KEY `N_id` (`N_id`), CONSTRAINT `A_ibfk_1` FOREIGN KEY (`N_id`) REFERENCES `N` (`N_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `B` ( `B_id` int(11) NOT NULL AUTO_INCREMENT, `D_id` int(11) NOT NULL, `E_id` int(11) NOT NULL, `C_id` int(11) NOT NULL, `Z_id` int(11) NOT NULL, PRIMARY KEY (`B_id`), KEY `C_id` (`C_id`), KEY `D_id` (`D_id`), KEY `E_id` (`E_id`), KEY `Z_id` (`Z_id`), CONSTRAINT `B_ibfk_1` FOREIGN KEY (`D_id`) REFERENCES `D` (`D_id`), CONSTRAINT `B_ibfk_2` FOREIGN KEY (`E_id`) REFERENCES `E` (`E_id`), CONSTRAINT `B_ibfk_3` FOREIGN KEY (`C_id`) REFERENCES `C` (`C_id`), CONSTRAINT `B_ibfk_4` FOREIGN KEY (`Z_id`) REFERENCES `Z` (`Z_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `C` ( `C_id` int(11) NOT NULL AUTO_INCREMENT, `E_id` int(11) NOT NULL, PRIMARY KEY (`C_id`), KEY `E_id` (`E_id`), CONSTRAINT `C_ibfk_1` FOREIGN KEY (`E_id`) REFERENCES `E` (`E_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `D` ( `D_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`D_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `E` ( `E_id` int(11) NOT NULL AUTO_INCREMENT, `D_id` int(11) NOT NULL, PRIMARY KEY (`E_id`), KEY `D_id` (`D_id`), CONSTRAINT `E_ibfk_1` FOREIGN KEY (`D_id`) REFERENCES `D` (`D_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `F` ( `L_id` int(11) NOT NULL, `A_id` int(11) NOT NULL, PRIMARY KEY (`L_id`), KEY `A_id` (`A_id`), CONSTRAINT `F_ibfk_1` FOREIGN KEY (`A_id`) REFERENCES `A` (`A_id`), CONSTRAINT `F_ibfk_2` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `G` ( `L_id` int(11) NOT NULL, `O_id` int(11) NOT NULL, PRIMARY KEY (`L_id`), KEY `O_id` (`O_id`), CONSTRAINT `G_ibfk_1` FOREIGN KEY (`O_id`) REFERENCES `O` (`O_id`), CONSTRAINT `G_ibfk_2` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `H` ( `L_id` int(11) NOT NULL, PRIMARY KEY (`L_id`), CONSTRAINT `H_ibfk_1` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `I` ( `L_id` int(11) NOT NULL, PRIMARY KEY (`L_id`), CONSTRAINT `I_ibfk_1` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `J` ( `J_id` int(11) NOT NULL AUTO_INCREMENT, `L_id` int(11) NOT NULL, `N_id` int(11) NOT NULL, PRIMARY KEY (`J_id`), KEY `L_id` (`L_id`), KEY `N_id` (`N_id`), CONSTRAINT `J_ibfk_1` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`), CONSTRAINT `J_ibfk_2` FOREIGN KEY (`N_id`) REFERENCES `N` (`N_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `K` ( `J_id` int(11) NOT NULL, PRIMARY KEY (`J_id`), CONSTRAINT `K_ibfk_1` FOREIGN KEY (`J_id`) REFERENCES `J` (`J_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `L` ( `L_id` int(11) NOT NULL AUTO_INCREMENT, `O_id` int(11) NOT NULL, PRIMARY KEY (`L_id`), KEY `O_id` (`O_id`), CONSTRAINT `L_ibfk_1` FOREIGN KEY (`O_id`) REFERENCES `O` (`O_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `M` ( `M_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`M_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `N` ( `N_id` int(11) NOT NULL AUTO_INCREMENT, `O_id` int(11) NOT NULL, `M_id` int(11) NOT NULL, PRIMARY KEY (`N_id`), KEY `M_id` (`M_id`), KEY `O_id` (`O_id`), CONSTRAINT `N_ibfk_1` FOREIGN KEY (`O_id`) REFERENCES `O` (`O_id`), CONSTRAINT `N_ibfk_2` FOREIGN KEY (`M_id`) REFERENCES `M` (`M_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `O` ( `O_id` int(11) NOT NULL AUTO_INCREMENT, `B_id` int(11) NOT NULL, `Z_id` int(11) NOT NULL, PRIMARY KEY (`O_id`), KEY `B_id` (`B_id`), KEY `Z_id` (`Z_id`), CONSTRAINT `O_ibfk_1` FOREIGN KEY (`B_id`) REFERENCES `B` (`B_id`), CONSTRAINT `O_ibfk_2` FOREIGN KEY (`Z_id`) REFERENCES `Z` (`Z_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `P` ( `P_id` int(11) NOT NULL AUTO_INCREMENT, `L_id` int(11) DEFAULT NULL, PRIMARY KEY (`P_id`), KEY `L_id` (`L_id`), CONSTRAINT `P_ibfk_1` FOREIGN KEY (`L_id`) REFERENCES `L` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `Q` ( `R_id` int(11) NOT NULL, `P_id` int(11) DEFAULT NULL, PRIMARY KEY (`R_id`), KEY `P_id` (`P_id`), CONSTRAINT `Q_ibfk_1` FOREIGN KEY (`R_id`) REFERENCES `R` (`R_id`), CONSTRAINT `Q_ibfk_2` FOREIGN KEY (`P_id`) REFERENCES `P` (`P_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `R` ( `R_id` int(11) NOT NULL AUTO_INCREMENT, `L_id` int(11) NOT NULL, PRIMARY KEY (`R_id`), KEY `L_id` (`L_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `S` ( `S_id` int(11) NOT NULL AUTO_INCREMENT, `U_id` int(11) NOT NULL, `field_1` decimal(13,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`S_id`), KEY `U_id` (`U_id`), CONSTRAINT `S_ibfk_1` FOREIGN KEY (`U_id`) REFERENCES `U` (`U_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `T` ( `S_id` int(11) NOT NULL, `N_id` int(11) NOT NULL, PRIMARY KEY (`S_id`), KEY `N_id` (`N_id`), CONSTRAINT `T_ibfk_1` FOREIGN KEY (`S_id`) REFERENCES `S` (`S_id`), CONSTRAINT `T_ibfk_2` FOREIGN KEY (`N_id`) REFERENCES `N` (`N_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `U` ( `U_id` int(11) NOT NULL AUTO_INCREMENT, `field_2` varchar(50) NOT NULL, `field_3` varchar(100) NOT NULL, PRIMARY KEY (`U_id`), KEY `field_3` (`field_3`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `V` ( `V_id` int(11) NOT NULL AUTO_INCREMENT, `Y_id` int(11) NOT NULL, `Z_id` int(11) DEFAULT NULL, PRIMARY KEY (`V_id`), KEY `V_id` (`V_id`), KEY `Y_id` (`Y_id`), KEY `field_4` (`Y_id`), KEY `field_5` (`Y_id`), KEY `field_6` (`Y_id`), KEY `Z_id` (`Z_id`), CONSTRAINT `V_ibfk_1` FOREIGN KEY (`Y_id`) REFERENCES `Y` (`Y_id`), CONSTRAINT `V_ibfk_2` FOREIGN KEY (`Z_id`) REFERENCES `Z` (`Z_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `W` ( `X_id` int(11) NOT NULL, `S_id` int(11) NOT NULL, PRIMARY KEY (`S_id`), KEY `X_id` (`X_id`), CONSTRAINT `W_ibfk_1` FOREIGN KEY (`X_id`) REFERENCES `X` (`X_id`), CONSTRAINT `W_ibfk_2` FOREIGN KEY (`S_id`) REFERENCES `S` (`S_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `X` ( `X_id` int(11) NOT NULL AUTO_INCREMENT, `V_id` int(11) NOT NULL, PRIMARY KEY (`X_id`), KEY `V_id` (`V_id`), CONSTRAINT `X_ibfk_1` FOREIGN KEY (`V_id`) REFERENCES `V` (`V_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `Y` ( `Y_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Y_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `Z` ( `Z_id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Z_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `C` VALUES (1,1),(2,1),(3,1),(4,4); INSERT INTO `D` VALUES (1),(2),(3),(4); INSERT INTO `E` VALUES (1,1),(2,1),(3,1),(4,4); INSERT INTO `M` VALUES (1),(2),(3),(4); INSERT INTO `Z` VALUES (1),(2),(3),(4);