SQL Server 中是否有只列出主键的视图?
我正在使用 SQL Server 并尝试做一些“反思”,如果你愿意的话。我找到了系统视图 sys.identity_columns,它包含我所有表的所有标识列。
但是,我需要能够选择有关非标识列的主键的信息。是否有包含所有主键数据且仅包含主键数据的视图?如果没有,我还能如何获取这些数据?
I'm working with SQL Server and trying to do a little "reflection," if you will. I've found the system view sys.identity_columns
, which contains all of the identity columns for all of my tables.
However, I need to be able to select information about primary keys that aren't identity columns. Is there a view that contains data about all primary keys and only primary keys? If not, how else can I get this data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这适用于 SQL Server 2005 及更高版本:
This works for SQL Server 2005 and higher:
我意识到该问题已被标记为已回答,但对某些人展示如何合并 sys.index_columns 可能也会有所帮助(除了 sys.indexes 之外)到您的查询,以便将实际的主键索引与表的列联系起来。例子:
i realize that the question has already been marked as answered, but it might also be helpful to some to show how to incorporate
sys.index_columns
(in addition tosys.indexes
) to your query in order to tie the actual primary key index to the table's columns. example:试试这个...
Try this...