問題
使用 TABLE_CONSTRAINTS 取得Table的PK
解決方法
SQL語法:
SELECT TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_SCHEMA, TABLE_NAME結果如下:
若要指定哪一個TABLE
SELECT TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY'--加上這句 AND TABLE_NAME=資料表名稱AND TABLE_NAME='TABLE1' ORDER BY TABLE_SCHEMA, TABLE_NAME
沒有留言:
張貼留言