-- --------------------------------- -- Use this in advance to create the db structure -- --------------------------------- CREATE TABLE `gruppen` ( `id_gruppe` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL, PRIMARY KEY (`id_gruppe`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; CREATE TABLE `gruppe_eigenschaften` ( `id_gruppe` int(11) NOT NULL, `name` varchar(30) NOT NULL, `wert` varchar(30) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- --------------------------------- -- This is how you get 1) a new auto_increment-id for a gruppe, -- then 2) you set the last_insert_id as variable in mysql, -- then 3) you use that variable in the following statements. -- --------------------------------- SET FOREIGN_KEY_CHECKS = 0; INSERT INTO gruppen (name) VALUES ('Gruppe 1'); SET @temp_gruppe_id = LAST_INSERT_ID(); INSERT INTO gruppe_eigenschaften (id_gruppe, name, wert) VALUES (@temp_gruppe_id, 'email1', 'email1@emailxxx.com'); INSERT INTO gruppe_eigenschaften (id_gruppe, name, wert) VALUES (@temp_gruppe_id, 'email2', 'email2@emailxxx.com'); -- and many more using the set @temp_gruppe_id INSERT INTO gruppen (name) VALUES ('Gruppe 2'); SET @temp_gruppe_id = LAST_INSERT_ID(); INSERT INTO gruppe_eigenschaften (id_gruppe, name, wert) VALUES (@temp_gruppe_id, 'email1', 'email1@emailyyy.com'); -- and many more using the set @temp_gruppe_id SET FOREIGN_KEY_CHECKS = 1; -- ---------------------------------