sql server 删除表及表的相关视图、存储过程、方法

时间:2021-10-01 06:00:35

注意:进行此操作前需先备份数据库,免得删错无法恢复

1.查询

SELECT
Name
,type
FROM SysObjects
WHERE name LIKE '%cases%'

2.拼接语句

SELECT
'drop Procedure '+
Name
FROM SysObjects
WHERE name LIKE '%cases%'
AND type='p'; SELECT
'drop view '+
Name
FROM SysObjects
WHERE name LIKE '%cases%'
AND type='v'; SELECT
'drop table '+
Name
FROM SysObjects
WHERE name LIKE '%cases%'
AND type='u'; SELECT
'drop function '+
Name
FROM SysObjects
WHERE name LIKE '%cases%'
AND type='fn'

3.执行删除语句