获得sql列名

 

获得列名

 

select   name   from   syscolumns   where   id=object_id('ds_field')


或  


select col_name(object_id('table'),1) from sysobjects where name='table'  

 

--读取库中的所有表名


select name from sysobjects where xtype='u'

 

--读取指定表的所有列名


select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='表名')

 

 

方法如下:先从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

自己修改如下,可以直接放到JSP中执行
SELECT name
FROM syscolumns
WHERE (id =
(SELECT id
FROM sysobjects
WHERE (id = OBJECT_ID('YOURTABLENAME'))))
ORDER BY colid

你可能感兴趣的:(sql)