create table job_lists ( job_list_id bigint unsigned not null primary key auto_increment, name varchar(100) not null, unique(name) ) engine=innodb charset=utf8; create table jobs ( job_id bigint unsigned not null primary key auto_increment, job_list_id bigint unsigned not null, reference_key varchar(100) not null, data text, is_started tinyint not null default 0, started_on timestamp null, is_completed tinyint not null default 0, completed_on timestamp null, unique(job_list_id, reference_key), foreign key fk_jobs_to_job_lists (job_list_id) references job_lists (job_list_id) on delete cascade ) engine=innodb charset=utf8;