比方說我有「問題羣」如何保持共同的父母表的參照完整性?
GroupID | value --------+------ 42 | How often do you 9071 | Other question ...
一個表,併爲每個小組的問題,我有「問題」和「可能的答案」
Group | QuestionID | value ------+------------+------ 42 | 5 | ... brush your teeth? 42 | 89 | ... go to the movies? 9071 | 709 | ... another question ... ...
Group | Answer | value ------+--------+------ 42 | 134 | several times per day 42 | 135 | twice a day 42 | 71 | once a day 42 | 803 | every other day 42 | 8 | once a week 42 | 666 | once a month ...
現在,在PHP/HTML中,我做了一個(虛擬)完整的跨組問題和42組可能的答案以構建一個2入口表,用戶將在其中選擇他/她的答案(HTML version)
How often do you | N/d | 2/d | 1/d | d*2 | 1/w | 1/m | ----------------------+-----+-----+-----+-----+-----+-----+ ... brush your teeth? | () | (X) | () | () | () | () | ... go to the movies? | () | () | () | () | (X) | () |
我知道我需要
insert into answers (question, answer, ...) values (5, 135, ...)
牙齒
和
insert into answers (question, answer, ...) values (89, 8, ...)
電影
的問題是:有沒有辦法強制執行,這兩個問題和答案,在answers
表, 「屬於」同一組問題?
我想這
insert into answers (question, answer, ...) values (709, 71, ...)
被禁止的,因爲問題709「屬於」組9071和回答71屬於組42
如果我理解正確,你需要在答案表**上有一個**約束,該約束表明答案的組等於問題的組。檢查你的數據庫幫助,看看如何精確地寫這個... – KLE