(MS SQL Server)SQL语句导入导出大全(11)

发布时间: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

(MS SQL Server)SQL语句导入导出大全(11).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219