策码奔腾

postgreSql查询主键字段sql语句

select kcu.table_schema,
       kcu.table_name,
       tco.constraint_name,
       kcu.ordinal_position as position,
       kcu.column_name as key_column
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu 
     on kcu.constraint_name = tco.constraint_name
     and kcu.constraint_schema = tco.constraint_schema
     and kcu.constraint_name = tco.constraint_name
where tco.constraint_type = 'PRIMARY KEY'
and kcu.table_schema='public' and 
         kcu.table_name='table';

 

posted @ 2021-06-15 18:35  策码奔腾  阅读(1642)  评论(0编辑  收藏  举报
console.log('欢迎');