Using the sp_msforeachtable
stored procedure, you can execute a script for all tables in the database.
However, there are system tables that I would like to exclude from this. Instinctively, I would check the IsSystemTable
or IsMSShipped
. They do not work, as I expect, for example, I have a table called __RefactorLog
:
But when I query if it is a system or MS-sent table, SQL Server does not report any of my system table tables:
exec (N'EXEC Database..sp_msforeachtable "PRINT ''? = '' + CAST(ObjectProperty(Object_ID(''?''), ''IsSystemTable'') AS VARCHAR(MAX))"') AS LOGIN = 'MyETLUser' -- Results of IsSystemTable: [dbo].[__RefactorLog] = 0 [schema].[myUserTable] = 0
and
exec (N'EXEC Database..sp_msforeachtable "PRINT ''? = '' + CAST(ObjectProperty(Object_ID(''?''), ''IsMSShipped'') AS VARCHAR(MAX))"') AS LOGIN = 'MyETLUser' -- Results of IsMSShipped: [dbo].[__RefactorLog] = 0 [schema].[myUserTable] = 0
When I look at the properties of a table (inside SSMS), the table is marked as a system object. An object property, such as IsSystemObject
, does not exist (AFAIK).
How to check if a table is a system object other than an object property? How does SSMS check if a table is a system object?
source share