日期:2014-05-18  浏览次数:20428 次

如何获取数据库表的所有列名?
譬如,表名:USER,如何获取USER表的所有列名?

------解决方案--------------------

select name from syscolumns where id=object_id('user')
------解决方案--------------------
select name from syscolumns where id=object_id('USERS')
------解决方案--------------------
select name from syscolumns
where object_id('USER')=id
------解决方案--------------------
SQL code

declare @str varchar(1000)
select @str=''
select @str=@str+','+name from syscolumns where id=object_id('user')
select stuff(@str,1,1,'')

------解决方案--------------------
select name 
from syscolumns 
where id=object_id( 'users ')
-------------------------------------
name
id
name
sex
departmentid
isorder
department
jobtitleid
jobtitle
company
groupcompany
companyen
provinceid
cityid
address
postcode
telephone
fax
mobile
email
territoryid
territory
companysizeid
companyweb
salesname
customertype
region
level
t2000
t25000
global250
global300
ma
pma
sme
nep
cem
pat
generaloptin
executiveBoardroom
bigAdmin
innerCircle
eduConnection
interestproduct
createdate
dataState
accounttype
productperformace
Edu
CourseCode
CourseDate
CourseType
CourseCat
Elite
T1
T2
T3
activetime
enterbasetime
olm
UID