查找外键的最快方法与 Management Studio 中的哪个表相关?

发布于 2024-08-15 03:00:00 字数 253 浏览 7 评论 0原文

我想知道是否有更快的方法:

“我打开了 Management Studio,并且有一个 Db 表,其中列的鬃毛列在我前面。我知道 FK_SomeTable 字段是一个外键。但我不知道它是哪个表上的 FK。”

因此,通常我会打开该表的“关系”,在由丑陋的窄窗口框出的列表中逐一浏览并尝试。在那里找到它,这有点无聊而且浪费时间。

我也不想查询系统表。

难道就没有更好更快的方法吗?应该有吧?

谢谢

I wonder if there is a quicker way for this:

"I have my Management Studio open and I have a Db table with manes of columns listed in front of me. I know FK_SomeTable field is a ForeignKey. But I do not know it is an FK on what table. And I need to learn that."

So, normally I open the "Relationships" of that table, go one by one in the list which is framed by ab ugly narrow window and try to find it there, which is kind of boring and time loosing.

I do not want to query the system tables as well.

Isn't there a better and quicker way? There should be, isn't it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野却迷人 2024-08-22 03:00:00

这个查询怎么样?您可以翻转到查询窗口并快速执行它:

SELECT
    name,
    OBJECT_NAME(parent_object_id) 'Parent Table',
    OBJECT_NAME(referenced_object_id) 'Referenced Table'
FROM sys.foreign_keys

为您提供 FK 名称以及涉及的两个表。

如果需要,还有一个 sys.foreign_key_columns 系统目录视图可以为您提供列信息。

How about this query? You could flip over to a query window and execute it quickly:

SELECT
    name,
    OBJECT_NAME(parent_object_id) 'Parent Table',
    OBJECT_NAME(referenced_object_id) 'Referenced Table'
FROM sys.foreign_keys

Gives you the FK name, and the two tables involved.

There's also a sys.foreign_key_columns system catalog view to give you the column information, if needed.

人间☆小暴躁 2024-08-22 03:00:00

如果打开数据库图表,您可以同时创建和更改多个表的关系。数据库图表显示所选每个表的可视化表示,并且您可以定义多个图表。据我所知,没有任何方法可以在不查询系统表的情况下检索关系信息。

If you turn on database diagrams, you can create and alter the relationships of multiple tables simultaneously. Database diagrams show visual representations of each table selected, and you can define multiple diagrams. As far as I know thought there is not any method of retrieving relationship information without querying the system tables.

后知后觉 2024-08-22 03:00:00

嗯,我通常使用对象资源管理器并转到我想要的表,然后在“键”下查看。您可以扩大对象资源管理器以查看密钥的全名。如果命名正确,它可能包含主键表和外键表的表名。如果没有你可以编写脚本来查看。我必须搜索才能找到您所说的关系窗口,因为在编写所有更改的脚本时我永远不会使用设计窗口。

Well I usually use the object explorer and go to the table I want and then look under Keys. You can widen the object explorer to see the fullname of the key. If it is named properly it probably has the table name of both the primary key and foreign key tables in it. If not you can script it to see. I had to search to find this relationships window you were talking about becasue I would never use the design window as we script all changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文