代码之家  ›  专栏  ›  技术社区  ›  mehdi lotfi

SQL Server dbo.sysdiagram是用户表或系统表

  •  24
  • mehdi lotfi  · 技术社区  · 10 年前

    在简单数据库中使用数据库关系图时,SQL Server会在 Table\Systam Tables 节点(在Microsoft management studio\object explorer中)。但sysdiagram表在SQL Server中标记为用户表。您可以通过下面的查询获得用户表。

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

    enter image description here

    我不知道sysdiagram表是系统表还是用户表。

    存在 microsoft_database_tools_support 具有值 1 在sysdiagram的扩展属性中,确定自动创建的此表。

    enter image description here

    2 回复  |  直到 10 年前
        1
  •  18
  •   Maxim    9 年前

    Management Studio在确定“系统对象”时使用了以下方法,其中“tbl”是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]
    
        2
  •  12
  •   Zev Spitz    9 年前

    SQL Server在内部使用系统表,它们在每个用户数据库中都是相同的。

    从服务器的角度来看,sysdiagram不是系统表。

    但SQLServerManagementStudio创建它来存储关系图数据,因此它也将其分类为系统表。

    您可以使用您提到的扩展属性排除此类系统表。