首頁 >資料庫 >mysql教程 >获取表的primary key

获取表的primary key

WBOY
WBOY原創
2016-06-07 14:56:431345瀏覽

获取SQL Server表的primary key 无 SELECT cu.Column_NameFROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS t LEFT JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu ON t.CONSTRAINT_NAME = cu.CONSTRAINT_NAME AND cu.TABLE_NAME = t.TABLE_NAMELEFT JOIN IN

获取SQL Server表的primary key
SELECT cu.Column_Name
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS t 
	LEFT JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu ON t.CONSTRAINT_NAME = cu.CONSTRAINT_NAME AND cu.TABLE_NAME = t.TABLE_NAME
	LEFT JOIN INFORMATION_SCHEMA.COLUMNS c ON c.COLUMN_NAME = cu.COLUMN_NAME AND c.TABLE_NAME = cu.TABLE_NAME
WHERE Constraint_Type = 'PRIMARY KEY ' AND cu.Table_Name = '<table name>'
ORDER BY c.ORDINAL_POSITION
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn