IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_describe_table]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_describe_table]
GO

--======================================================
--张小猛 2018118
--======================================================
create proc mps_describe_table(@tabname varchar(100))
as
begin

select
        c.object_id,
        o.name,
        c.name,
        tp.name as [datatype],
        c.max_length,
        c.is_computed,
        c.precision,
        c.scale as scale,
        c.collation_name,
        c.is_nullable,
        dc.definition,
        ic.is_identity,
        ic.seed_value,
        ic.increment_value
    from
        sys.columns c
        join sys.types tp on c.user_type_id = tp.user_type_id
        left join sys.computed_columns cc on c.object_id = cc.object_id and c.column_id = cc.column_id
        left join sys.default_constraints dc on
            c.default_object_id != 0
            and c.object_id = dc.parent_object_id
            and c.column_id = dc.parent_column_id
        left join sys.identity_columns ic on c.is_identity = 1 and c.object_id = ic.object_id and c.column_id = ic.column_id
        left join sys.objects o on o.object_id = c.object_id 
    where o.name = @tabname
    order by
        ic.is_identity desc,
        c.name
        
end