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
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