读书人

SQL透过if else判断后插入不同语句

发布时间: 2013-04-21 21:18:07 作者: rapoo

SQL通过if else判断后插入不同语句
if not exists (select * from syscolumns where id = object_id('student') and name = 'remark')
begin
insert (number,name,age) into values('60024597','张三',21)
end
else
begin
insert (number,name,age remark) into values('60024597','张三',21)
end

这样的语句,如果student表不存在列remark执行的时候就会提示李明remark无效,如何解决呢?

不使用储存过程啊

我的临时解决方案是存在先增加列,插入后,通过判断NULL值删除列

请高手指导啊



读书人网 >SQL Server

热点推荐