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
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
alter table _Crm_Company Add [CustomCode] nvarchar(50) not null default ''
go
update _Crm_Company set CustomCode = EnglishName
if not exists( select [name] from syscolumns where id=object_id('_Crm_Company') and [name] = 'CustomCode' )
begin
alter table _Crm_Company Add [CustomCode] nvarchar(50) not null default ''
update _Crm_Company set CustomCode = EnglishName
end
drop table crm_company
gocreate table crm_company(f1 int)
go
insert into crm_company values(1)
goif not exists( select [name] from syscolumns where id=object_id('Crm_Company') and [name] = 'CustomCode' )
begin
alter table Crm_Company Add [CustomCode] nvarchar(50) not null default '' update Crm_Company set CustomCode = 'df'
end
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
47522341(睡到8:30) 我这里执行不对啊
------------------------
忘了说明我的是sql 2005了
GO
/****** 对象: Table [dbo].[Authors] 脚本日期: 01/19/2007 13:32:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter table [dbo].[Authors] Add [CustomCode] nvarchar(50) not null default ''
GO
update [dbo].[Authors] set [CustomCode] = [Name]这样可以。
我是SQL SERVER 2005 我用的DUWAMISH7的库测试的
USE [Duwamish7]
GO
/****** 对象: Table [dbo].[Authors] 脚本日期: 01/19/2007 13:32:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GOif not exists( select [name] from syscolumns where id=object_id('Authors') and [name] = 'CustomCode' )
begin
alter table [dbo].[Authors] Add [CustomCode] nvarchar(50) not null default ''
end
GO
update [dbo].[Authors] set [CustomCode] = [Name]
update [dbo].[Authors] set [CustomCode] = [Name]