如何判断一个表中的某一列是否已经存在?

SolidEst 2003-10-09 07:09:59
将列名作为参数,如何判断列是否已经存在?
...全文
110 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dennis618 2003-10-09
  • 打赏
  • 举报
回复
select case count(*) when 1 then '存在此列' else '不存在'end from syscolumns a left join sysobjects b on a.id=b.id where a.name='字段名' and b.name='表名'
pengdali 2003-10-09
  • 打赏
  • 举报
回复
if exists(select 1 from syscolumns where id=object_id('Table2') and name='列名')
select '在'
txlicenhe 2003-10-09
  • 打赏
  • 举报
回复
select o.name as oname, c.name as cnamefrom syscolumns c
join sysobjects o on o.id=c.id
where o.xtype='U' and o.name = '表名' and c.name = '字段名'

22,206

社区成员

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

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