SQL query to find Primary Key of a table?

前端 未结 8 479
耶瑟儿~
耶瑟儿~ 2021-02-04 01:30

How can I find which column is the primary key of a table by using a query?

8条回答
  •  旧巷少年郎
    2021-02-04 01:50

    The following query gives the list of all the primary keys in the given database.

    SELECT DISTINCT TABLE_NAME ,column_name
        FROM INFORMATION_SCHEMA.key_column_usage
        WHERE TABLE_SCHEMA IN ('*your_db_name*');
    

提交回复
热议问题