Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get primary key column names for a given table?

All I know is only table name, and id value on which I want to perform query, but I do not know what is id called in that table.

like image 348
rsk82 Avatar asked Aug 05 '10 09:08

rsk82


People also ask

How do you find which column is the primary key in a table?

Answer: You can retrieve primary key information with the following SQL statement: SELECT cols. table_name, cols. column_name, cols.

How do I get only column names from a table?

We will be using sys. columns to get the column names in a table. It is a system table and used for maintaining column information.

How do I get the column names of a table in SQL?

USE db_name; DESCRIBE table_name; it'll give you column names with the type.

How do I get a list of column names in a database?

SELECT * FROM INFORMATION_SCHEMA. COLUMNS WHERE COLUMN_NAME LIKE 'PREFIX%' ORDER BY TABLE_NAME; Query: SELECT * FROM INFORMATION_SCHEMA.


1 Answers

You can probably lookup the column name for the primary key column(s) using the answer to a quite similar question..

sqlite> pragma table_info(...)

It should also work programmatically, if needed.

like image 176
gnab Avatar answered Sep 28 '22 07:09

gnab