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日 濟南中迪智業。    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM