[转]不同版本的SQL Server之间数据导出导入的方法及性能比较
工作中有段时间常常涉及到不同版本的数据库间导出导入数据的问题,索性整理一下,并简单比较下性能,有所遗漏的方法也欢迎讨论、补充。 00.建立测试环境 01.使用SQL Server Import and Export Tool 02.使用Generate Scripts 03.使用BCP 04.使用SqlBulkCopy 0
工作中有段时间常常涉及到不同版本的数据库间导出导入数据的问题,索性整理一下,并简单比较下性能,有所遗漏的方法也欢迎讨论、补充。
00.建立测试环境
01.使用SQL Server Import and Export Tool
02.使用Generate Scripts
03.使用BCP
04.使用SqlBulkCopy
05.使用Linked Server进行数据迁移
06.使用RedGate的SQL Data Compare
07.结果对比
可以先看下测试的结果
00.建立测试环境
建立一个测试的环境,一个数据源数据库,香港服务器,版本为SQL Server 2008,一个目标数据库,版本为SQL Server 2000。
实验环境如下图所示,源数据库使用语句生成了100万的测试数据。
建立测试表并生成100万的测试数据
IF OBJECT_ID() IS NOT NULL DROP TABLE DEMOTABLE GO CREATE TABLE DEMOTABLE ( COL1 VARCHAR(50) , COL2 VARCHAR(50) , COL3 VARCHAR(50) ) INSERT INTO DEMOTABLE SELECT TOP 1000000 NEWID() , NEWID() , NEWID() FROM MASTER..SPT_VALUES T1 INNER JOIN MASTER..SPT_VALUES T2 ON 1 = 1 INNER JOIN MASTER..SPT_VALUES T3 ON 1 = 1
01.使用SQL Server Import and Export Tool
使用SQL Server Import and Export Tool进行数据的导出,也可以在目标数据库端使用Import进行导入,这部分套件也是SSIS的一部分。
在源数据库上右键,选择Task -> Export Data
分别填写源数据库和目标数据库的连接信息。
选择“copy data from one or more tables or views”
选择需要导数据的表,并且可以编辑列的Mapping关系。
可以选择立即执行或者存储为SSIS的包,用于执行计划等其他用途。
这里我们选择立即执行。
注意导入的时候如果遇到如下的错误
Error 0xc02020f4: Data Flow Task: The column "Tel" cannot be processed because more than one code page (936 and 1252) are specified for it.
(SQL Server Import and Export Wizard)
是因为两边的数据库的Collation设置不一样造成的,需要设置同样的Collation。
02.使用Generate Scripts生成脚本在源数据库上右键,选择Task -> Geneate Scripts...
配置相关信息,注意选择数据库的版本并将Script Data设置成True。
这里需要注意,美国空间,因为有100万的数据,香港空间,所以导出的SQL文件就有400多M,所以用SQL Server Management Studio是打不开的。
所以只能使用sqlcmd执行。
sqlcmd语句
C:\>sqlcmd -i export.sql -d ExportDataDemo_Destination -s 192.168.21.165 -U sa -P 1234567890
用时约28分钟
03.使用BCP进行导出导入
在尝试了前面两个效率低下的工具之后,我们终于开始尝试下SQL Server中专门用于导数据的工具:BCP。
关于BCP的详细用法可以参见MSDN的帮助文档。
我们先使用BCP导出数据。
-U和-P后面分别为数据库的用户名和密码。
我们可以看到100万的数据导出仅用了1.8秒。
现在我们再使用BCP进行导入。
执行后发现,导入数据使用了20.8秒,还是很快的。
.NET Framework 2.0中增加的SqlBulkCopy类可以进行高效的数据迁移动作,这也为代码实现数据迁移提供了接口。
并且SqlBulkCopy类提供了修改字段Mapping关系的方法ColumnMappings。
使用SqlBulkCopy类进行数据迁移

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,

The performance comparison of PHP array key value flipping methods shows that the array_flip() function performs better than the for loop in large arrays (more than 1 million elements) and takes less time. The for loop method of manually flipping key values takes a relatively long time.
