查询表字段信息 查询表主键

1、查询表字段信息:

            select name
            from syscolumns
            where id = object_id('table_name')
            order by colorder

2、查询主键信息:

            select column_name 
            from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE A
            inner join sysobjects B on A.constraint_name = B.name
            where B.parent_obj = object_id('table_name') 
            and B.xtype='PK'




你可能感兴趣的:(SQL,Server)