之前写了一个存储过程:可以查看标的列名,结构
现在用sql直接得出最后结果:
--获取所有的列名
declare @objid int,@objname varchar(20)
set @objname = 'DimKY' --要显示的表名
select @objid = id from sysobjects where id = OBJECT_ID(@objname)
--方法1
select 'col_name' = name from syscolumns where id = OBJECT_ID(@objname)
--方法2
select 'col_name' = name from syscolumns where id = @objid order by colid
select * from DimKY
--获取所有的列名
declare @objid int,@objname varchar(20)
set @objname = 'DimKY' --要显示的表名
select @objid = id from sysobjects where id = OBJECT_ID(@objname)
--方法1
select 'col_name' = name from syscolumns where id = OBJECT_ID(@objname)
--或者:
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='DimKY')