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日 济南中迪智业。
所有评论(0)