将数据从数据库插入到另一个数据库 [英] Insert data from db to another db

查看:56
本文介绍了将数据从数据库插入到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将旧数据库表中的值转移到新数据库表中.

I want to take values from my old database tables to new database tables.

旧的数据库结构:

表一:国家

  • 国家编号
  • 国家名称

新的数据库结构

表二:国家

  • 身份证
  • 姓名

我使用了以下插入查询,如

I used the following insert query like,

select 'insert into Countries (Id, Name) select ', countryid, countryname from Country

但我得到的结果是,

  • insert into countries(Id,Name) select 1 India
  • insert into countries(Id,Name) select 2 Any Country

就这样.

但我需要这样的结果,

insert into Countries (Id, Name) values (1, 'India')

要实现这一点,查询是什么?帮帮我...

To achieve this, what is the query? help me...

推荐答案

如果要传输的数据很多,并且有多个表,我建议使用 SQL Server Management Studio 提供的导入/导出向导.

If there is a lot of data to transfer and multiple tables, I would suggest using Import/Export wizard provided by SQL Server Management Studio.

http://www.mssqltips.com/sqlservertutorial/203/simple-way-to-import-data-into-sql-server/

但是,如果数据不是很多,并且两个系统没有连接 - 并且您需要生成脚本来传输数据,您的查询应该是这样的:

However, if there is not lot of data and the two systems are not connected - and you need to generate script to transfer data, your query should look like this:

SELECT 'INSERT INTO Countries (Id, Name) VALUES (' + CAST(countryid AS VARCHAR(50)) + ', ''' + countryname + ''')' from Country

这篇关于将数据从数据库插入到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆