Tải bản đầy đủ - 0 (trang)
5-6. Transferring Data Between SQL Server Databases Regularly

5-6. Transferring Data Between SQL Server Databases Regularly

Tải bản đầy đủ - 0trang

Chapter 5 ■ SQL Server Sources



6.



Click Connections in the list on the left and select the CarSales_Staging_OLEDB

destination connection.



7.



Select the dbo.Client destination table.



8.



In the Source Connection File field, select the BCPConnection defined in step 4. Once

complete, the dialog box should look like Figure 5-2.



Figure 5-2.  Bulk Insert with SSIS

9.

10.



Click Options in the pane on the left. Ensure that the data file type is set to widenative

(as this was the BCP export option chosen).

Select the Keep Nulls and Table Lock options. You should see a dialog box like

Figure 5-3.



257

www.it-ebooks.info



Chapter 5 ■ SQL Server Sources



Figure 5-3.  SSIS Bulk Insert task options

11.



Click OK to confirm your selections.



You can now run the SSIS package and load the data into SQL Server.



How It Works

SSIS can also perform BULK INSERTs of SQL Server source data in native format. A BULK INSERT task cannot

perform any data cleansing or data modification during the data load, however. Also, you must ensure that you

are using the type of native format (character or Unicode) that you specified when exporting the data itself.

Moreover, the destination table must exist before you can set up this package. This technique is quite possibly the

fastest load option available in SSIS.

This example used the default column and row terminators (tab and CR/LF). If these are set to anything

different as part of the BCP export command, then you need to ensure that the corresponding terminators are

chosen in the Connection pane of the BULK INSERT task editor. Similarly, if you have chosen—or been given—a

different data file type (native, character, or widechar) in the source file, you need to ensure that this maps to the

character type chosen in the BULK INSERT task.



258

www.it-ebooks.info



s



Hints, Tips, and Traps





If the source data is already sorted, then you can enter the column(s) composing the sort

keys at step 10 in the SortedData field.







If the destination table does not map exactly to the source table structure, or if you wish to

load only a subset of columns, then you have to define and use a format file.







There are many ways in which bulk loads of data using BCP, BULK INSERT, and

OPENROWSET (BULK) can be optimized. Please see Chapter 14 for details on bulk load

optimization.







BULK INSERT treats scientific-notation float data as invalid and gives conversion errors.

You must use a format file if faced with this problem.



5-7. Porting a Tiny Amount of Data Between SQL Server

Databases

Problem

You want to transfer a small amount of data between SQL Server databases quickly and easily without any

complex T-SQL or using SSIS.



Solution

Script out the data from SSMS as INSERT statements.

The following steps detail how you can carry out this operation.

1.



Right-click the database name. Select Tasks ➤ Generate scripts.



2.



Click Next if the introduction dialog box is displayed.



3.



Click Select Specific Objects. Expand Tables and check the table(s) whose data you

wish to script out. The dialog box should look something like Figure 5-4.



259

www.it-ebooks.info



Chapter 5 ■ SQL Server Sources



Figure 5-4.  Scripting data from SSMS

4.



Click Next, and then click Advanced. Find the Types of Data to Script option. Select

Data Only, as shown in Figure 5-5.



260

www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

5-6. Transferring Data Between SQL Server Databases Regularly

Tải bản đầy đủ ngay(0 tr)

×