--select * from syscolumns where [name]='invest'
select rtrim(b.name) as colname
,case when h.id is not null then 'PK' else '' end as primarykey
,type_name(b.xusertype) + case when b.colstat & 1 = 1 then '[ID(' + convert(varchar,ident_seed(a.name)) + ',' + convert(varchar,ident_incr(a.name)) + ')]' else '' end as type
,b.length
,case b.isnullable when 0 then 'N' else 'Y' end as [isnull]
,isnull(e.text,'') as [default]
,isnull(c.value,'') as descript 
from sysobjects a,syscolumns b 
left outer join sysproperties c on b.id = c.id and b.colid = c.smallid 
left outer join syscomments e on b.cdefault = e.id
left outer join (select g.id,g.colid from sysindexes f,sysindexkeys g where f.id = g.id and f.indid = g.indid and f.indid > 0 and f.indid < 255 and (f.status & 2048)<>0) h on b.id = h.id and b.colid = h.colid
where a.id = b.id
and a.id = object_id('invest') --tablename改成你要导出的表的名称
order by b.colid

解决方案 »

  1.   

    use 你的数据库
    select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='你的表名'
    INFORMATION_SCHEMA.COLUMNS 视图里有你要的所有东西
      

  2.   

    COL_NAME 
    返回列名。COL_LENGTH 
    返回列长度。
    学习以上两个函数吧
      

  3.   

    use 数据库名
    SELECT COL_NAME(OBJECT_ID('表名'), 1)
    ---'1'代表你这个表的第一个字段,可以是'2'那就是第二个.......
      

  4.   

    use '你的库名'
    EXEC sp_columns @table_name = '你的表名'
      

  5.   

    sp_help 表名'

    sp_columns '表名'

    EXEC sp_columns @table_name = '表名'