不同数据库查找表的主键
mysql查找表的主键
SELECT distinct column_name FROM INFORMATION_SCHEMA.`KEY_COLUMN_USAGE` WHERE table_name='你的表名'
AND constraint_name='PRIMARY';
oracle查找表的主键 注意oracle的表名和字段名都为大写
select column_name from all_cons_columns cc where owner='你的owner' and table_name='你的表名' and
exists (select 'x' from all_constraints c where c.owner = cc.owner and c.constraint_name = cc.constraint_name and c.constraint_type ='P')
order by position
postgreSql查找表的主键
select pg_attribute.attname as column_name 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 = '你的表名' and pg_constraint.contype='p'
数据库连接的客户端工具推荐使用Navicat Premium
oracle需要安装配置instantclient

浙公网安备 33010602011771号