user194076 user194076 - 1 year ago 217
SQL Question

How to exclude tables from sp_msforeachtable

I know that sp_msforeachtable allows to perform queries on all tables.
I have 100 tables and I want to perform the same query on 97 tables.
I'm using this query:

EXEC sp_MSForEachTable "DELETE FROM ?"

Is it possible to exclude certain tables?

Answer Source
EXEC sp_MSforeachtable 'IF OBJECT_ID(''?'') NOT IN (
                        DELETE FROM ?'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download