难呀,帮我...

cysh 2003-08-19 01:08:47
用什么语句可以查询出一个表中的所有字段.
...全文
28 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
z5wjz 2003-08-19
  • 打赏
  • 举报
回复
select * from syscolumns where id=object_id('yourtable')

or

sp_columns 'yourtable'
z5wjz 2003-08-19
  • 打赏
  • 举报
回复
select name from syscolumns
where object_id('yourtable')=id

or

sp_columns 'yourtable'
zjcxc 2003-08-19
  • 打赏
  • 举报
回复
如果你要查详细的表结构,就用

select c.name as 字段名
,t.name 数据类型
,c.prec as 长度
,p.value as 字段说明
,m.text as 默认值
from syscolumns c
inner join
systypes t
on c.xusertype=t.xusertype
left join
sysproperties p
on c.id=p.id and c.colid = p.smallid
left join
syscomments m
on c.cdefault=m.id
where objectproperty(c.id,'IsUserTable')=1
and object_id('你要查的表')=id
zjcxc 2003-08-19
  • 打赏
  • 举报
回复
select name from syscolumns where id=object_id('你要查的表')
lilu207 2003-08-19
  • 打赏
  • 举报
回复
select a.name ,b.name ,a.length, a.isnullable
from syscolumns a, systypes b,sysobjects d
where a.xtype=b.xusertype and a.id=d.id and d.xtype='u'
and a.id=object_id('pre_qyckmyb')
honsire 2003-08-19
  • 打赏
  • 举报
回复
EXEC sp_columns @table_name='yourtable'
hjb111 2003-08-19
  • 打赏
  • 举报
回复
sp_columns 'yourtablename'
select * from syscolumns where id=object_id('yourtable')
CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
select * from syscolumns where id=object_id('表名')


txlicenhe 2003-08-19
  • 打赏
  • 举报
回复
1:sp_columns 'yourTableName'
2:
我一般用这个视图
Create view fielddesc
as
select o.name as oname, c.name as cname,convert(varchar(30),p.value) as value,p.smallid as psmallid,t.name as tname
from syscolumns c
join systypes t on c.xtype = t.xtype
join sysobjects o on o.id=c.id
left join sysproperties p on p.smallid=c.colid and p.id=o.id
where o.xtype='U'

-- 调用: select * from fielddesc where oname = 'yourTableName'

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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