41 lines
1.5 KiB
Transact-SQL
41 lines
1.5 KiB
Transact-SQL
/* ============================================================================
|
|
删除策略冒烟测试夹具:清理(可重复执行,表不存在也能跑通)
|
|
----------------------------------------------------------------------------
|
|
注意两点,都是实测踩出来的:
|
|
1. 关系行必须按双向清理:冒烟会临时造反向关系(环路场景 smoke_order → smoke_order_item),
|
|
只删一个方向会留下指向已 drop 表的孤儿行。
|
|
2. 业务表的 delete 必须用 object_id 守卫:清理可重入,表已 drop 时直接 delete 会报
|
|
Invalid object name,而 RunSqlFile 是单事务、一批失败整体回滚,
|
|
会导致整个清理静默失效(前面几批的删除也被回滚)。
|
|
============================================================================ */
|
|
|
|
delete from dbo.s_delete_rule where b_module_id in ('smoke_order', 'smoke_order_item');
|
|
GO
|
|
|
|
/* 关系行:双向清理,避免孤儿关系 */
|
|
delete from dbo.s_relation
|
|
where b_source_module_id in ('smoke_order', 'smoke_order_item')
|
|
or b_target_module_id in ('smoke_order', 'smoke_order_item');
|
|
GO
|
|
|
|
delete from dbo.s_module where b_id in ('smoke_order', 'smoke_order_item');
|
|
GO
|
|
|
|
if object_id('dbo.smoke_order_item', 'U') is not null
|
|
begin
|
|
delete from dbo.smoke_order_item;
|
|
end
|
|
GO
|
|
|
|
if object_id('dbo.smoke_order', 'U') is not null
|
|
begin
|
|
delete from dbo.smoke_order;
|
|
end
|
|
GO
|
|
|
|
drop table if exists dbo.smoke_order_item;
|
|
GO
|
|
|
|
drop table if exists dbo.smoke_order;
|
|
GO
|