SQLite query to find primary keys

In SQLite, I can run the following query to get a list of columns in a table:

PRAGMA table_info(myTable) 

This gives me columns, but does not contain information about what primary keys may be. In addition, I can run the following two queries to search for indexes and foreign keys:

 PRAGMA index_list(myTable) PRAGMA foreign_key_list(myTable) 

But I can’t figure out how to view primary keys. Does anyone know how I can do this?

Note. I also know what I can do:

 select * from sqlite_master where type = 'table' and name ='myTable'; 

And he will give the create table statement, which shows the primary keys. But I'm looking for a way to do this without parsing the create statement.

+8
schema primary-key sqlite3
source share
1 answer

table_info will give you a column named pk (the last one) indicating whether it is the primary key (if so, the pointer in it) or not (zero).

To clarify, from the documentation:

The column "pk" in the result set is zero for columns that are not part of the primary key and is the index of the column in the primary key for columns that are part of the primary key.

+8
source share

All Articles