日期:2014-05-19  浏览次数:20597 次

为什么刚添加一列,就updata就报错?
alter   table   _Crm_Company   Add   [CustomCode]   nvarchar(50)   not   null   default   ' '
update   _Crm_Company   set   CustomCode   =   EnglishName

会报列不存在

后来改成这样也是


alter   table   _Crm_Company   Add   [CustomCode]   nvarchar(50)   not   null   default   ' '

while(   1   =   1   )
begin

WAITFOR   DELAY   '00:00:15 '

if   exists(   select   [name]   from   syscolumns   where   id=object_id( '_Crm_Company ')   and   [name]   =   'CustomCode '   )
begin
update   _Crm_Company   set   CustomCode   =   EnglishName
break
end
end

------解决方案--------------------
--try
if not exists( select [name] from syscolumns where id=object_id( '_Crm_Company ') and [name] = 'CustomCode ' )
alter table _Crm_Company Add [CustomCode] nvarchar(50) not null default ' '
go
update _Crm_Company set CustomCode = EnglishName