怎么取出一个sql数据库中的某个表的所有字段名

qianjunyi 2004-11-02 08:48:19
怎么取出一个sql数据库中的某个表的所有字段名
如:数据库Trade中的表System_Info
...全文
405 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
葶子宝贝 2004-11-04
  • 打赏
  • 举报
回复
exec sp_columns 'tablename'
该语句可以显示出此表的所有信息
qizhanfeng 2004-11-04
  • 打赏
  • 举报
回复
学习了
select * from database..dbo.syscolumns where id=object_id('tablename')
lzymagi 2004-11-04
  • 打赏
  • 举报
回复
select * from database..dbo.syscolumns where id=object_id('tablename')
afanyun 2004-11-04
  • 打赏
  • 举报
回复
--如果要取到变量中

declare @s varchar(8000)
set @s=''
select @s=@s+','+name from dbo.syscolumns where id=(select id from dbo.sysobjects where name='System_Info')
set @s=stuff(@s,1,1,'')
select @s
afanyun 2004-11-04
  • 打赏
  • 举报
回复
select name from dbo.syscolumns
where id=(select id from dbo.sysobjects where name='System_Info')
enewren 2004-11-03
  • 打赏
  • 举报
回复
select * from syscolumns where id in(select id from sysobjects where name ='tablename' and xtype='u')
zjcxc 2004-11-02
  • 打赏
  • 举报
回复
--如果要取到变量中
declare @s varchar(8000)
set @s=''
select @s=@s+','+name from Trade.dbo.sysobjects where name='System_Info'
set @s=stuff(@s,1,1,'')
print @s
zjcxc 2004-11-02
  • 打赏
  • 举报
回复
select 字段名=name from Trade.dbo.sysobjects where name='System_Info'
pbsql 2004-11-02
  • 打赏
  • 举报
回复
select name from Trade.dbo.syscolumns where id=object_id(N'System_Info')

27,579

社区成员

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

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