sql如何获取某一个表的所有字段名,并且有一个字段的统计数

wwfdn 2010-05-20 09:22:38
sql如何获取某一个表的所有字段名,并且有一个字段的统计数
...全文
17560 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
fb1zwb 2011-04-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 htl258 的回复:]

SQL code
select 字段顺序='字段'+ltrim(colid),字段名=name from syscolumns where id=object_id('tb')
union all
select '合计',ltrim(count(1)) 统计数 from syscolumns where id=object_id('tb')
/*
字段顺序 ……
[/Quote]
写的很明白了
wyx100 2011-02-06
  • 打赏
  • 举报
回复
dim testrs,testsql,i
set testrs=server.createobject("adodb.recordset")
testsql=" select * from 表名称 "
testrs.open testsql,conntoall,1,1

if testrs.eof or testrs.bo……
  • 打赏
  • 举报
回复
通过系统表来实现,主要的问题还在于2005和2008与2000版本的系统表变化差异太大,建议楼主多看看关于系统表的内容。
-晴天 2011-01-23
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 sk_chin 的回复:]
弱弱的问一句为什么不用这种方式:

dim testrs,testsql,i
set testrs=server.createobject("adodb.recordset")
testsql=" select * from 表名称 "
testrs.open testsql,conntoall,1,1

if testrs.eof or testrs.bo……
[/Quote]
这样做,你知道这些数据的"字段名"吗?
sk_chin 2011-01-23
  • 打赏
  • 举报
回复
弱弱的问一句为什么不用这种方式:

dim testrs,testsql,i
set testrs=server.createobject("adodb.recordset")
testsql=" select * from 表名称 "
testrs.open testsql,conntoall,1,1

if testrs.eof or testrs.bof then
response.write "没有数据!"
else
for i=1 to testrs.Fields.count
response.write testrs.Fields(i-1).Name
response.write chr(10)
next
end if

testrs.close
set testrs=nothing
weihao20090930 2010-05-20
  • 打赏
  • 举报
回复
select name from syscolumns where id=object_id('表名')

select count(1) 统计数 from syscolumns where id=object_id('表名')
htl258_Tony 2010-05-20
  • 打赏
  • 举报
回复
还是要整在一个表:

select 字段顺序='字段'+ltrim(colid),字段名=name  from syscolumns where id=object_id('tb')
union all
select '合计',ltrim(count(1)) 统计数 from syscolumns where id=object_id('tb')
/*
字段顺序 字段名
---------- ------------------------------------
字段1 ID
字段2 WEBpage
合计 2

(3 行受影响)
*/
weiki516 2010-05-20
  • 打赏
  • 举报
回复
答案1楼已经给了
永生天地 2010-05-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 htl258 的回复:]
SQL code
select name from syscolumns where id=object_id('表名')

select count(1) 统计数 from syscolumns where id=object_id('表名')
[/Quote]
合一下就行了
黄_瓜 2010-05-20
  • 打赏
  • 举报
回复

--2005
select name from sys.columns where object_id=object_id('表名')
select max(column_id) from sys.columns where object_id=object_id('表名')
htl258_Tony 2010-05-20
  • 打赏
  • 举报
回复
select name from syscolumns where id=object_id('表名')

select count(1) 统计数 from syscolumns where id=object_id('表名')

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧