以前客户有个旧系统,数据放在sql 7.0中,现在想把以前的数据倒到新的系统中,用的sql server 2000,请问有啥好的办法!

loulanlouzhu 2004-01-13 12:05:12
两者的数据结构不一样了!
...全文
71 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
loulanlouzhu 2004-01-13
  • 打赏
  • 举报
回复
那以前的数据就没法用了!?
zjcxc 2004-01-13
  • 打赏
  • 举报
回复
--然后用下面的方法进行复制.

/*--数据库数据复制

将一个数据库中的数据复制到另一个数据库
如果某列在目标数据库中为标识列,将不会被复制

适用范围:数据库结构发生了变化,想将旧数据库进行升级
这样就可以根据新的数据库结构创建一个空库,然后
将旧数据库的所有数据复制到新库中
--邹建 203.10--*/

/*--调用示例

exec p_copydb '源数据库','目标数据库'
exec p_copydb 'acc_五医','acc_演示数据8'
--*/

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_copydb]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_copydb]
GO

create proc p_copydb
@o_dbname sysname, --要复制数据的数据库--源数据库
@n_dbname sysname, --接收数据的数据库--目标数据库
@cleardb bit=0 --清空目标数据库
as
declare @sql nvarchar(4000)

--禁用约束,防止复制时的数据冲突
set @sql='declare #tbc cursor for select name,tbname=object_name(parent_obj)
from '+@n_dbname+'..sysobjects where xtype in(''C'',''F'')'
exec(@sql)
declare @name sysname,@tbname sysname
open #tbc
fetch next from #tbc into @name,@tbname
while @@fetch_status=0
begin
set @sql='alter table '+@n_dbname+'..['+@tbname+'] NOCHECK CONSTRAINT ['+@name+']'
exec(@sql)
fetch next from #tbc into @name,@tbname
end
close #tbc

--复制数据
declare @sql1 varchar(8000)
set @sql='declare #tb cursor for select a.name from '
+@o_dbname+'..sysobjects a inner join '
+@n_dbname+'..sysobjects b on a.name=b.name
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+'',[''+a.name+'']'' from(
select name from '+@o_dbname+'..syscolumns where id in
(select id from '+@o_dbname+'..sysobjects where name='''+@tbname+''')
) a inner join (
select name from '+@n_dbname+'..syscolumns where status<>0x80 and id in
(select id from '+@n_dbname+'..sysobjects where name='''+@tbname+''')
) b on a.name=b.name'
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 @name,@tbname
while @@fetch_status=0
begin
set @sql='alter table '+@n_dbname+'..['+@tbname+'] CHECK CONSTRAINT ['+@name+']'
exec(@sql)
fetch next from #tbc into @name,@tbname
end
close #tbc
deallocate #tbc
go


zjcxc 2004-01-13
  • 打赏
  • 举报
回复
将7.0的数据库备份一下,然后在2000中恢复.
txlicenhe 2004-01-13
  • 打赏
  • 举报
回复
结构都不一样那还搞什么?

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧