SELECT 
 字段名=a.name 
FROM syscolumns a
 left join systypes b on a.xusertype=b.xusertype
 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 sysproperties g on a.id=g.id and a.colid=g.smallid  
 left join sysproperties f on d.id=f.id and f.smallid=0
where d.name='表A' and COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1   
order by a.id,a.colorder

解决方案 »

  1.   

    SELECT 
     字段名=a.name 
    FROM syscolumns a
     left join systypes b on a.xusertype=b.xusertype
     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 sysproperties g on a.id=g.id and a.colid=g.smallid  
     left join sysproperties f on d.id=f.id and f.smallid=0
    where d.name='Orders' and COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1    --如果只查询指定表,加上此条件
    order by a.id,a.colorder
      

  2.   

    --是这样
    SELECT 
     字段名=a.name 
    FROM syscolumns a
     left join systypes b on a.xusertype=b.xusertype
     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 sysproperties g on a.id=g.id and a.colid=g.smallid  
     left join sysproperties f on d.id=f.id and f.smallid=0
    where d.name='表A' and COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1   
    order by a.id,a.colorder