fcf92675b1
Deploy / deploy (push) Successful in 1m13s
用 BINARY 比较绕过 utf8mb4_unicode_ci 与 utf8mb4_0900_ai_ci 的冲突。 shop code 均为纯 ASCII,BINARY 比较结果完全一致。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
33 lines
1.5 KiB
SQL
33 lines
1.5 KiB
SQL
-- clear_shop.sql — 清空指定门店的所有业务数据
|
|
-- 用法(调用方负责传入 @shop_code 变量):
|
|
-- SET @shop_code = 'S001'; SOURCE clear_shop.sql;
|
|
-- 或由脚本拼接:
|
|
-- echo "SET @shop_code='S001';" | cat - clear_shop.sql | mysql ...
|
|
|
|
SET @sid = (SELECT id FROM shops WHERE BINARY code = BINARY @shop_code LIMIT 1);
|
|
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
DELETE FROM inventory_check_items WHERE shop_id = @sid;
|
|
DELETE FROM inventory_checks WHERE shop_id = @sid;
|
|
DELETE FROM inventory_logs WHERE shop_id = @sid;
|
|
DELETE FROM inventories WHERE shop_id = @sid;
|
|
DELETE FROM stock_out_items WHERE shop_id = @sid;
|
|
DELETE FROM stock_out_orders WHERE shop_id = @sid;
|
|
DELETE FROM stock_in_items WHERE shop_id = @sid;
|
|
DELETE FROM stock_in_orders WHERE shop_id = @sid;
|
|
DELETE FROM finance_records WHERE shop_id = @sid;
|
|
DELETE FROM number_rules WHERE shop_id = @sid;
|
|
DELETE FROM product_images WHERE shop_id = @sid;
|
|
DELETE FROM partners WHERE shop_id = @sid;
|
|
DELETE FROM warehouses WHERE shop_id = @sid;
|
|
DELETE FROM product_spec_options WHERE shop_id = @sid;
|
|
DELETE FROM product_series_options WHERE shop_id = @sid;
|
|
DELETE FROM product_name_options WHERE shop_id = @sid;
|
|
DELETE FROM products WHERE shop_id = @sid;
|
|
DELETE FROM product_categories WHERE shop_id = @sid;
|
|
DELETE FROM users WHERE shop_id = @sid;
|
|
DELETE FROM shops WHERE id = @sid;
|
|
|
|
SET FOREIGN_KEY_CHECKS = 1;
|