通过脚本添加字段不成功

jashionqq 2012-04-25 11:55:47
/*create table test(
lxh int,
msg varchar(80)
)
*/

if not exists (select name from syscolumns where id = object_id('test') and name = 'ss')
begin
alter table test add ss int default(0);
update test set ss = lxh;
end;
执行脚本后报错,报错信息如下:
消息 207,级别 16,状态 1,第 0 行
列名 'ss' 无效。
另:if not exists (select name from syscolumns where id = object_id('test') and name = 'ss')
begin
alter table test add ss int default(0);
--update test set ss = test.lxh;
end;
执行这句脚本是成功的
...全文
118 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wujianfeng32 2012-04-25
  • 打赏
  • 举报
回复
ss=''
TracyLeebaihe 2012-04-25
  • 打赏
  • 举报
回复

if not exists (select name from syscolumns where id = object_id('test') and name = 'ss')
alter table test add ss int default(0);
go
update test set ss = [入库];
go

这样保你成功
simonxt 2012-04-25
  • 打赏
  • 举报
回复

if not exists (select name from syscolumns where id = object_id('test') and name = 'ss')
begin
alter table test add ss int default(0);
exec('update test set ss = lxh;')
end;



这样呢?
jashionqq 2012-04-25
  • 打赏
  • 举报
回复
感谢simonxt的回复,按照你的做法就成功了,谢谢。

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧