答案 0 :(得分:0)
我更喜欢使用INFORMATION_SCHEMA:
SELECT C.TABLE_CATALOG,
C.TABLE_SCHEMA,
C.TABLE_NAME,
C.COLUMN_NAME,
C.DATA_TYPE,
C.COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS C
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE U
ON C.TABLE_CATALOG = U.TABLE_CATALOG
AND C.TABLE_SCHEMA = U.TABLE_SCHEMA
AND C.TABLE_NAME = U.TABLE_NAME
AND C.COLUMN_NAME = U.COLUMN_NAME
WHERE OBJECTPROPERTY(OBJECT_ID(U.CONSTRAINT_SCHEMA + '.' + QUOTENAME(U.CONSTRAINT_NAME)), 'IsPrimaryKey') = 1
AND C.DATA_TYPE = 'uniqueidentifier'
AND C.COLUMN_DEFAULT IS NULL