读书人

为什么刚添加一列就updata就报错?解

发布时间: 2012-01-23 21:57:28 作者: rapoo

为什么刚添加一列,就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

读书人网 >SQL Server

热点推荐