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值删除列
请高手指导啊
------解决方案--------------------
if not exists (select * from syscolumns where id = object_id('student') and name = 'remark')
begin
EXEC('insert into student (number,name,age) values(''60024597'',''张三'',21)')
end
else
begin
insert into student (number,name,age,remark)values('60024597','张三',21,'2012年毕业')
end
------解决方案--------------------
if not exists (select * from syscolumns where id = object_id('student') and name = 'remark')
begin
insert into student (number,name,age) values('60024597','张三',21)
end
else
begin
insert into student (number,name,age,remark)values('60024597','张三',21,'2012年毕业')
end
运行之后的结果正常......