CREATE PROCEDURE [Common].[ProcLoadColumnInfo]
@inObjectName sysname
AS
BEGIN
SELECT TableCatalog = DB_NAME() ,
TableSchema = SCHEMA_NAME(C.schema_id) ,
TableName = D.name ,
ColumnName = A.name ,
ColumnPosition = A.colorder ,
DataType = B.name ,
MaximumLength = A.length ,
MaxLength = COLUMNPROPERTY(A.id, A.name, 'PRECISION') ,
NumericScale = ISNULL(COLUMNPROPERTY(A.id, A.name, 'SCALE'), 0) ,
IsIdentity = CASE WHEN COLUMNPROPERTY(A.id, A.name,
'ISIDENTITY') = 1 THEN 1
ELSE 0
END ,
IsPrimary = CASE WHEN EXISTS ( SELECT 1
FROM sys.indexes idx ,
sys.index_columns idxCol
WHERE idx.object_id = A.id
AND idx.is_primary_key = 1
AND idxCol.column_id = A.colid
AND idx.index_id = idxCol.index_id
AND idx.object_id = idxCol.object_id )
THEN 1
ELSE 0
END ,
IsNullable = A.isnullable ,
ColumnDefault = ISNULL(E.text, '') ,
ColumnDescription = ISNULL(G.[value], '')
FROM syscolumns A
LEFT JOIN systypes B ON A.xtype = B.xusertype
INNER JOIN sys.objects C ON A.id = C.object_id
INNER JOIN sysobjects D ON A.id = D.id
AND D.xtype = 'U'
AND D.name <> 'DTPROPERTIES'
LEFT JOIN syscomments E ON A.cdefault = E.id
LEFT JOIN sys.extended_properties G ON A.id = G.major_id
AND A.colid = G.minor_id
AND G.name = 'MS_DESCRIPTION'
WHERE A.id = OBJECT_ID(@inObjectName)
ORDER BY A.id ,
A.colorder;
END;
GO