SQL---retrieve table's infomation fields by fields

 the following sql plus retrieves the  table's infomation fields by fields,you just need pass the table name;

 

代码
   
     
select syscolumns.name as ColName
,systypes.name
as ColTypeName ,
syscolumns.length, sys.extended_properties.value
as Mark ,
syscolumns.isnullable
as AllowNull ,IsPK = Case when exists
(
select 1 from sysobjects inner join sysindexes on sysindexes.name = sysobjects.name
inner join sysindexkeys on sysindexes.id = sysindexkeys.id
and sysindexes.indid = sysindexkeys.indid where xtype = ' PK ' and parent_obj = syscolumns.id
and sysindexkeys.colid = syscolumns.colid )
then 1 else 0 end ,IsIdentity = Case syscolumns.status
when 128 then 1 else 0 end from syscolumns
inner join systypes on ( syscolumns.xtype = systypes.xtype
and systypes.name <> ' _default_ ' and systypes.name <> ' sysname ' )
left outer join sys.extended_properties on ( sys.extended_properties.major_id = syscolumns.id
and minor_id = syscolumns.colid ) where syscolumns.id =
(
select id from sysobjects where name = 'table_name' ) order by syscolumns.colid

 

 

 

你可能感兴趣的:(table)