SQL Server dbo.sysdiagrams is a user table or system table

那年仲夏 提交于 2019-12-06 17:02:48

问题


When use Database Diagrams in a simple database, SQL Server create a dbo.sysdiagrams table in the Table\Systam Tables node (in Microsoft management studio\object explorer). But sysdiagrams table marked as user table in SQL Server. you can get user table by below query.

SELECT * 
FROM sys.tables t
WHERE OBJECTPROPERTY(t.object_id,'IsUserTable') = 1

I don't know that sysdiagram table is a system table or is a user table.

Exists microsoft_database_tools_support with value 1 In the extended property of sysdiagram, that determine this table created automatically.


回答1:


System tables are used internally by the SQL Server, they are the same in every user database.

sysdiagrams is not a system table from the server point of view.

But SQL Server Management Studio creates it to store the diagram data, so it also categorizes it as a system table.

You can exclude such kinda system tables using the extended attribute you mentionned.




回答2:


Management Studio utilizes the following in its determination of "System Objects" where "tbl" is sys.tables:

CAST(
 case 
    when tbl.is_ms_shipped = 1 then 1
    when (
        select 
            major_id 
        from 
            sys.extended_properties 
        where 
            major_id = tbl.object_id and 
            minor_id = 0 and 
            class = 1 and 
            name = N'microsoft_database_tools_support') 
        is not null then 1
    else 0
end          
             AS bit) AS [IsSystemObject]


来源:https://stackoverflow.com/questions/22270328/sql-server-dbo-sysdiagrams-is-a-user-table-or-system-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!