看板 Database 關於我們 聯絡資訊
個位大大你好. 請問, 在 mysql 指定 FOREIGN KEY, 可以幫忙操作 刪除/更新 的動作馬? Example : table 'product' - product_id - name table 'product_description' - product_id (FK) - description table 'product_options' - product_id (FK) - option_name 我刪除時候, 若只是知道 'product' 這個 table, 包含他的 product_id, 我可以刪除其他所有 entry 在 product_description 與 product_option 嗎? 我不想在 sql syntax 裡面有提到 其他 table 的名字. 若可以這樣做我覺得會很方便. 資料庫是新手, 才幾個月接觸到. 所以希望可以多多交流. 謝謝. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.195.1.240
TeemingVoid:建立 foreign key constraint 時,多加上 on update 11/10 13:39
TeemingVoid:cascade on delete cascade 選項即可 11/10 13:39
TeemingVoid:另外,因為是 MySQL,請留意 engine 要用 InnoDB 11/10 13:40