当前位置: 代码迷 >> Sql Server >> 怎么判断表中是否存在一字段
  详细解决方案

怎么判断表中是否存在一字段

热度:18   发布时间:2016-04-24 21:04:39.0
如何判断表中是否存在一字段
如题。我的Sql2005
我在网上查的应该是

  if not exists(select * from syscolumns where id=object_id('JL_PonderationBill') and name='[UpdaterCode]')
   Select 1
else
   Select 0

但是为什么会返回1呢,表中明明有这个字段

谢谢朋友了。

------解决方案--------------------
引用:

  if not exists(select * from syscolumns where object_id=object_id('JL_PonderationBill') and name='[UpdaterCode]')
   Select 1
else
   Select 0

看错了。你的那个应该是对了。
你可以先运行
select * from syscolumns where id=object_id('JL_PonderationBill') and name='UpdaterCode'
或者
select * from sys.columns where object_id=object_id('JL_PonderationBill') and name='UpdaterCode'
应该是多了[]这个符号吧。
  相关解决方案