col1,col2,col3....为非标识列 insert into B库..CT(col1,col2,col3....) select col1,col2,col3.... from A库..CT
第一种: 可把两个库中标识列先删后添 alter table CT drop column 标识 alter table CT add 标识 identity(1,1) int 再用: col1,col2,col3....为非标识列 insert into B库..CT(col1,col2,col3....) select col1,col2,col3.... from A库..CT go 第二种: use A go declare @Str varchar(3000) set @Str='' select @Str=@Str+','+name from syscolumns where id=object_id('CT') where name<>标识列字段名 set @Str=substring(@Str,2,len(@Str)) exec('insert into B库..CT('+@Str+') select '+@Str+' from A库') go
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'B..CT' 中为标识列指定显式值。
出现这个错误?
insert into B库..CT(col1,col2,col3....) select col1,col2,col3.... from A库..CT
可把两个库中标识列先删后添 alter table CT drop column 标识
alter table CT add 标识 identity(1,1) int
再用:
col1,col2,col3....为非标识列
insert into B库..CT(col1,col2,col3....) select col1,col2,col3.... from A库..CT
go
第二种:
use A
go
declare @Str varchar(3000)
set @Str=''
select @Str=@Str+','+name from syscolumns where id=object_id('CT')
where name<>标识列字段名
set @Str=substring(@Str,2,len(@Str))
exec('insert into B库..CT('+@Str+') select '+@Str+' from A库')
go