如何从 sp_msforeachtable 中排除表 [英] How to exclude tables from sp_msforeachtable
本文介绍了如何从 sp_msforeachtable 中排除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道 sp_msforeachtable
允许对所有表执行查询.
I know that sp_msforeachtable
allows to perform queries on all tables.
我有 100 个表,我想对 97 个表执行相同的查询.
I have 100 tables and I want to perform the same query on 97 tables.
我正在使用这个查询:EXEC sp_MSForEachTable "DELETE FROM ?"
I'm using this query: EXEC sp_MSForEachTable "DELETE FROM ?"
是否可以排除某些表?
推荐答案
EXEC sp_MSforeachtable 'IF OBJECT_ID(''?'') NOT IN (
ISNULL(OBJECT_ID(''[dbo].[T1]''),0),
ISNULL(OBJECT_ID(''[dbo].[T2]''),0)
)
DELETE FROM ?'
这篇关于如何从 sp_msforeachtable 中排除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文