簡體   English   中英

我們如何識別兩個SQL Server表之間的關系,一對一或其他關系......?

[英]How can we identify the relationship between two SQL Server tables , either one to one or some other relationship…?

我們如何識別兩個SQL Server表之間的關系,一對一或其他一些關系.....?

在SQL Server中,在數據庫中創建一個新視圖,添加要查看其關系的兩個表。

在此輸入圖像描述

如果您想檢查所有表連接到表的內容,只需右鍵單擊表並轉到查看依賴項

查看表的依賴關系 並找出答案。 您可以通過檢查該表的創建查詢來檢查所有約束。

檢查查詢中的所有表標簽約束

我認為它會幫助你。 謝謝

您可以使用Microsoft系統視圖來實現此目的:

SELECT  
    obj.name AS fk
    ,sch.name AS [schema_name]
    ,tabParent.name AS [table]
    ,colParent.name AS [column]
    ,tabRef.name AS [referenced_table]
    ,colRef.name AS [referenced_column]
FROM sys.foreign_key_columns fkc
JOIN sys.objects obj ON obj.object_id = fkc.constraint_object_id
JOIN sys.tables tabParent ON tabParent.object_id = fkc.parent_object_id
JOIN sys.schemas sch ON tabParent.schema_id = sch.schema_id
JOIN sys.columns colParent ON colParent.column_id = parent_column_id AND colParent.object_id = tabParent.object_id
JOIN sys.tables tabRef ON tabRef.object_id = fkc.referenced_object_id
JOIN sys.columns colRef ON colRef.column_id = referenced_column_id AND colRef.object_id = tabRef.object_id
JOIN sys.schemas schRef ON tabRef.schema_id = schRef.schema_id
WHERE schRef.name = N'dbo'
AND tabRef.name = N'Projects'

可以通過引用的表或列過濾此查詢,或者僅查找引用特定列的所有內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM