查询表的主键,这个问题困惑了我好长时间,到网上查资料,也没有一些比较可行的办法,郁闷的要死,数据库的操作难以继续,今天我的问题终于有了答案,希望可以给大家带来一点帮助。
1
1:利用SQL自带的存储过程
2![](/Images/OutliningIndicators/None.gif)
3
EXEC sp_pkeys @table_name='表名'
4![](/Images/OutliningIndicators/None.gif)
5
2:利用系统表INFORMATION_SCHEMA.KEY_COLUMN_USAGE
6![](/Images/OutliningIndicators/None.gif)
7
SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME='表名'
8![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)