PostgreSQL数据库中获取表主键名称

 

PostgreSQL数据库中获取表主键名称

 

一、如下表示,要获取teacher表的主键信息:

select pg_constraint.conname as pk_name,pg_attribute.attname as colname,pg_type.typname as typename from 
pg_constraint  inner join pg_class 
on pg_constraint.conrelid = pg_class.oid 
inner join pg_attribute on pg_attribute.attrelid = pg_class.oid 
and  pg_attribute.attnum = pg_constraint.conkey[1]
inner join pg_type on pg_type.oid = pg_attribute.atttypid
where pg_class.relname = 'teacher' 
and pg_constraint.contype='p'

 

二、效果图:

由图可知,主键约束的名称为pk_teacher,主键字段(列)为"id",主键字段的类型为:uuid。

 

 ——宋兴柱发表于2015年7月30日 济南中迪智业。    

转载于:https://www.cnblogs.com/songxingzhu/p/4689449.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值