SELECT cols.column_name FROM all_constraints cons, all_cons_columns cols WHERE cons.constraint_type = 'P' AND cons.constraint_name = cols.constraint_name AND cons.table_name = cols.table_name AND cons.owner = cols.owner AND cons.table_name='my_table_name' AND cons.owner='my_schema_name' See ... Read more
Tag Archives: get primary key
How to get primary key of a table from DB2
SELECT COLNAME FROM syscat.COLUMNS WHERE tabschema='my_schema_name' AND tabname='my_table_name' AND KEYSEQ=1 See also: How to get primary key of a table from PostgreSQL How to get primary key of a table from SQLite How to get primary key of a table from MySQL How to get primary key of a table ... Read more
How to get primary key of a table from SQL Server
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + CONSTRAINT_NAME), 'IsPrimaryKey') = 1 AND TABLE_NAME = 'my_table_name' AND TABLE_SCHEMA = 'my_schema_name' See also: How to get primary key of a table from PostgreSQL How to get ... Read more
How to get primary key of a table from MySQL
select COLUMN_NAME,INDEX_NAME from INFORMATION_SCHEMA.STATISTICS where TABLE_SCHEMA = 'my_schema_name' and TABLE_NAME='my_table_name' and INDEX_NAME='PRIMARY' See also: How to get primary key of a table from PostgreSQL How to get primary key of a table from SQLite How to get primary key of a ... Read more
How to get primary key of a table from SQLite
Run PRAGMA table_info('my_table_name') find the record that column ‘pk’ is 1, it’s the primary key. See also: How to get primary key of a table from PostgreSQL How to get primary key of a table from MySQL How to get primary key of a table from SQL Server How to get primary key ... Read more
How to get primary key of a table from PostgreSQL
SELECT pg_attribute.attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) FROM pg_index, pg_class, pg_attribute, pg_namespace WHERE pg_class.oid = 'my_table_name'::regclass AND indrelid = pg_class.oid AND nspname = 'my_schema_name' AND pg_class.relnamespace = pg_namespace.oid ... Read more