我有兩個DB tabels形成從Planung一個父子關係Aufgabe:查找每個父ID重複
Planung:
CREATE TABLE `planung` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`Bezeichnung` varchar(255) DEFAULT NULL,
-- lots of ohter columns
PRIMARY KEY (`id`),
) ENGINE=InnoDB
Aufgabe:
CREATE TABLE `aufgabe` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`planung_id` bigint(20) DEFAULT NULL, -- foreign key to Planung.id
`Nummer` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
-- lots of ohter columns
) ENGINE=InnoDB
我期待對於一個查詢給我所有Planung.id和Aufgabe.ID的所有重複Nummer per Planung。或者換句話說:對於每個Planung Aufgabe.Nummer都必須是獨一無二的,我想檢查一下這是否屬於我的數據庫(我知道它不是)。
您可能會考慮在表aufgabe上使用由'planung_id,nummer'組成的唯一索引。 (當然,你清理後)。 – dgw 2012-02-24 12:52:55