How to exclude a system table when querying Sys.Tables?

I run this SQL:

SELECT S.name as Owner, T.name as TableName FROM  sys.tables AS T
JOIN sys.schemas AS S ON S.schema_id = T.schema_id

And the result:

Owner   TableName
------------------------
dbo         Person
dbo         Customer
dbo         sysdiagrams

sysdiagramsis system table, but shown as a result.

Update: Thanks to everyone for your answers and comments, I use the answers of Nate Bolam and vmvadivel :

SELECT S.name as Owner, T.name as TableName 
FROM  
  sys.tables AS T
    INNER JOIN sys.schemas AS S ON S.schema_id = T.schema_id
    LEFT JOIN sys.extended_properties AS EP ON EP.major_id = T.[object_id]
WHERE 
  T.is_ms_shipped = 0 AND 
  (EP.class_desc IS NULL OR (EP.class_desc <>'OBJECT_OR_COLUMN' AND 
  EP.[name] <> 'microsoft_database_tools_support'))
+5
source share
3 answers

SSMS uses an extended property to mark the sysdiagrams table as a kind of pseudo-system table.

Try the following:

SELECT S.name as Owner, T.name as TableName FROM  sys.tables AS T
INNER JOIN sys.schemas AS S ON S.schema_id = T.schema_id
LEFT JOIN sys.extended_properties AS EP ON EP.major_id = T.[object_id]
WHERE (EP.class_desc IS NULL 
OR (EP.class_desc <> 'OBJECT_OR_COLUMN'
    AND EP.[name] <> 'microsoft_database_tools_support'))
+8
source

You can use for this IS_MS_SHIPPED. Hope the below script is what you are looking for

SELECT 
    S.[name] AS Owner, 
    T.[name] AS TableName 
FROM  
    sys.tables AS T JOIN sys.schemas AS S 
    ON S.schema_id = T.schema_id
WHERE 
    T.is_ms_shipped = 0 
    AND T.[name] <> 'sysdiagrams'
+3
source

,

SELECT S.name as Owner, T.name as TableName FROM  sys.tables AS T
JOIN sys.schemas AS S ON S.schema_id = T.schema_id
WHERE T.name <> 'sysdiagrams'
+1

All Articles