SQL query to find Primary Key of a table?

前端 未结 8 469
耶瑟儿~
耶瑟儿~ 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:39

    LEFT joining table_constraints seems to take more time on mine. i use Information_schema.COLUMNS

    SELECT TABLE_SCHEMA , TABLE_NAME , COLUMN_NAME FROM Information_schema.Columns WHERE COLUMN_KEY = "PRI" AND TABLE_SCHEMA = DATABASE()

提交回复
热议问题