方法如下:先从SYSTEMOBJECT系统表中取得数据表的SYSTEMID,然后再SYSCOLUMN表中取得该数据表的所有列名。
SQL语句如下:
declare @objid int,@objname char(40)
set @objname = 'tablename'
select @objid = id from sysobjects where id = object_id(@objname)
select 'Column_name' = name from syscolumns where id = @objid order by colid
--
除表的列名,还列出该列的类型及长度(本例为最多4位):
select 'Column_name' = tsc.name, 'Colume_type' = tst.name + '(' + convert(char(4),tst.length) + ')'
from syscolumns tsc, systypes tst
where id = @objid AND tsc.xtype = tst.xtype
order by colid
转载于:https://www.cnblogs.com/snorde/archive/2006/09/14/504012.html