Sql Server如何查询一个表的主键?

[复制链接]
查看11 | 回复4 | 2020-4-12 16:36:33 | 显示全部楼层 |阅读模式
可以参考下面的代码SELECT t.* from user_cons_columns t where t.table_name= '表名' and t.position is not null; --表名必zd须大写,如:TABLE_TEST,column即为用户的主键,user_cons_columns即为用户要的主键名。扩展资料:SQL语句添加主键Alter table tabname add primary key(col)说明:删除主键:Alter table tabname d...
回复

使用道具 举报

千问 | 2020-4-12 16:36:33 | 显示全部楼层
把鼠标放到表名上,然后按住Ctrl后点击鼠标左键,跳出表结构窗口,如下图,查看Keys就可以了。...
回复

使用道具 举报

千问 | 2020-4-12 16:36:33 | 显示全部楼层
如果方便的话,可以查看表结构。或者利用系统表sysobjects查询。select * from sysobjects where parent_obj in (select id from sysobjects where name='表名') and xtype='pk'...
回复

使用道具 举报

千问 | 2020-4-12 16:36:33 | 显示全部楼层
用系统表查:select * from sysobjects where parent_obj in (select id from sysobjects where name='表名') and xtype='pk'...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行