|
-- 查看删除Product
SHOW CREATE TABLE bf_product\G;
SELECT id,name from bf_product;
-- ①删除BugHistory
DELETE FROM bf_bug_history WHERE bugaction_id IN (SELECT id FROM bf_bug_action WHERE buginfo_id IN (SELECT id FROM bf_bug_info WHERE product_id IN(7,8,9,10)));
-- ②删除BugAction
DELETE FROM bf_bug_action WHERE buginfo_id IN (SELECT id FROM bf_bug_info WHERE product_id IN(7,8,9,10));
-- ③删除BugInfo
DELETE FROM bf_bug_info WHERE product_id IN(9,7,8,10);
-- ④删除MapProductUser
DELETE FROM bf_map_product_user WHERE product_id IN(9,7,8,10);
-- ⑤删除MapProductGroup
DELETE FROM bf_map_product_group WHERE product_id IN(9,7,8,10);
-- 删除外键约束
ALTER table bf_product_module DROP FOREIGN KEY bf__fk_PRODUCTMODULE_PRODUCT1;
ALTER table bf_product_module DROP FOREIGN KEY bf__fk_PRODUCTMODULE_PRODUCTMODULE1;
-- ⑥删除ProductModule(需删除外键约束,然后添加外键约束)
DELETE FROM bf_product_module WHERE product_id IN(9,7,8,10);
-- 添加外键约束
ALTER TABLE bf_product_module ADD CONSTRAINT `bf__fk_PRODUCTMODULE_PRODUCT1` FOREIGN KEY (`product_id`) REFERENCES `bf_product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
ALTER TABLE bf_product_module ADD CONSTRAINT `bf__fk_PRODUCTMODULE_PRODUCTMODULE1` FOREIGN KEY (`parent_id`) REFERENCES `bf_product_module` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-- 删除CaseAction
DELETE FROM bf_case_action WHERE caseinfo_id IN (SELECT id from bf_case_info WHERE product_id IN(9,7,8,10));
-- 删除外键
ALTER table bf_case_info DROP FOREIGN KEY bf__fk_case_info_product1;
-- ⑧删除CaseInfo
DELETE FROM bf_case_info WHERE product_id IN(9,7,8,10);
-- 添加外键
ALTER TABLE bf_case_info ADD CONSTRAINT `bf__fk_case_info_product1` FOREIGN KEY (`product_id`) REFERENCES `bf_product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-- 删除Product
DELETE FROM bf_product WHERE id IN (9,7,8,10);
|
|