(MS SQL Server)SQL语句导入导出大全(11)
发布时间:2021-06-06
发布时间:2021-06-06
fetch next from #tbc into @tbname
end
close #tbc
--复制数据
declare @sql1 varchar(8000)
set @sql='declare #tb cursor for select from '
+@o_dbname+'..sysobjects a inner join '
+@n_dbname+'..sysobjects b on =
where a.xtype=''U'' and b.xtype=''U'''
exec(@sql)
open #tb
fetch next from #tb into @tbname
while @@fetch_status=0
begin
select @sql1=''
,@sql='select @sql1=@sql1+'',[''++'']'' from(
select name from '+@o_dbname+'..syscolumns where id in
(select id from '+@o_dbname+'..sysobjects where name='''+@tbname+''') ) ainner join (
select name from '+@n_dbname+'..syscolumns where status<>0x80 and id in (select id from '+@n_dbname+'..sysobjects where name='''+@tbname+''') ) b on ='
exec sp_executesql @sql,N'@sql1 nvarchar(4000) out',@sql1 out
select @sql1=substring(@sql1,2,8000)
exec('insert into '+@n_dbname+'..['+@tbname+']('+@sql1
+') select '+@sql1+' from '+@o_dbname+'..['+@tbname+']')
if @@error<>0
print('insert into '+@n_dbname+'..['+@tbname+']('+@sql1
+') select '+@sql1+' from '+@o_dbname+'..['+@tbname+']')
fetch next from #tb into @tbname
end
close #tb
deallocate #tb
--数据复制完成后启用约束
open #tbc
fetch next from #tbc into @tbname
while @@fetch_status=0
begin
set @sql='alter table '+@n_dbname+'..['+@tbname+'] CHECK CONSTRAINT ALL' exec(@sql)
set @sql='alter table '+@n_dbname+'..['+@tbname+'] enable trigger ALL' exec(@sql)
fetch next from #tbc into @tbname
上一篇:2014广东省高考压轴卷 文科数学 Word版含解析
下一篇:抵押合同(公司)