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

怎么同时判断表是否存在以及字段是否存在

热度:76   发布时间:2016-04-24 08:50:18.0
如何同时判断表是否存在以及字段是否存在
我想要删除某个字段,sql语句如下
IF EXISTS(select ObjectProperty(Object_ID( 'students'),'IsUserTable')) ALTER TABLE students DROP COLUMN status

但这个语句只能判断表是否存在,并未判断表下面的字段是否存在.结果导致我在执行批量语句的时候总是中断.如何在以上语句中在加入字段是否存在的判断呢?

------解决思路----------------------
IF EXISTS(select * from sys.tables where name ='students') and 
   exists(select * from sys.columns where object_id = object_id('students') and name = 'status')
   ALTER TABLE students DROP COLUMN status
  相关解决方案