SELECT isc.COLUMN_NAME
,DATA_TYPE
,CHARACTER_MAXIMUM_LENGTH
,c.is_identity
,c.is_nullable
,CASE
WHEN ccu.COLUMN_NAME IS NULL
THEN 0
ELSE 1
END AS is_primary
FROM INFORMATION_SCHEMA.COLUMNS isc
INNER JOIN [sys].[columns] c ON isc.COLUMN_NAME = c.NAME
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON
tc.TABLE_NAME =
isc.TABLE_NAME
AND tc.CONSTRAINT_TYPE
= 'Primary Key'
LEFT JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON
tc.CONSTRAINT_NAME =
ccu.Constraint_name
AND ccu.COLUMN_NAME = isc.COLUMN_NAME
WHERE isc.TABLE_NAME = 'aspnet_users'
AND c.OBJECT_ID = OBJECT_ID(isc.TABLE_NAME)The output is:-
Tags
SQL SERVER