Getting PrimaryKeys & Their DataTypes

Use this Stored procedure to get all the PKs for all the tables at your database and their types as well, I excluded type 'sysType' as it's duplicated at sysColumns system table :

Create Proc GetPrimaryKeysTypes as

select table_name As [Table],column_name As PrimaryKey, As DataType from INFORMATION_SCHEMA.KEY_COLUMN_USAGE P
INNER JOIN SysObjects O On P.Table_Name = O.Name
INNER JOIN SysColumns C On P.Column_name = C.Name
INNER join SysTypes T On C.xtype = T.xtype
where O.Id = C.Id and <> 'sysname'
order by T.Name, P.Table_Name

Links to this post:

Create a Link