SQL中取得表中主键或其它信息

取得表中主键:
select primaryKey=COLUMN_NAME from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE
WHERE CONSTRAINT_NAME=(select CONSTRAINT_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE='PRIMARY KEY' AND TABLE_NAME='表名')
 
取得表的其它有用信息: select * from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE

你可能感兴趣的:(sql)