Presentation is loading. Please wait.

Presentation is loading. Please wait.

©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 1 of 23 Objectives In this lesson, you will learn to: Perform bulk copy using the BCP.

Similar presentations


Presentation on theme: "©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 1 of 23 Objectives In this lesson, you will learn to: Perform bulk copy using the BCP."— Presentation transcript:

1 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 1 of 23 Objectives In this lesson, you will learn to: Perform bulk copy using the BCP utility. Perform data transfer using the DTS wizard.

2 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 2 of 23 BCP The transfer of data from an external source to SQL Server is performed using the Bulk Copy Program utility.

3 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 3 of 23 Requirements of BCP Here are the requirements for the successful implementation of BCP: The data file containing the imported data needs to be in a row- column format. The data file should have row and column terminators so that SQL Server can understand the same while transferring data. The structure of the data file and SQL Server table need to be identical

4 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 4 of 23 Pre-requisites for BCP The following are the pre-requisites for successful BCP: The data in the data file must be of the text-only (character) format, or a format previously generated by the BCP utility. The destination and the source table must have relevant permissions to bulk copy data.

5 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 5 of 23 BCP Syntax BCP [[database_name.][owner].]table_name{in|out|format} data_file [-m max_errors] [-e err_file] [-b batch_size] [-C code_page] [-i input_file] [-o output_file] [-S server_name] [-U login_id] [-P password] [-T] [-k] [-E]

6 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 6 of 23 BULK INSERT Like BCP, the BULK INSERT statement can also be used to transfer data from a data file to a SQL Server table. To transfer data from a SQL Server table to a data file, BCP is a better option. BULK INSERT statements can be executed from the command prompt or from the query analyzer as part of a transaction. With the BULK INSERT statement you can insert data from a single source or multiple sources to a SQL Server table. The table into which data is being inserted can be an empty table or a table that already contains data.

7 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 7 of 23 Demonstration-Transferring Data from an External Source to a Table Problem Statement A list containing College details have been gathered and stored on a flat file -College.txt. These details have to be transferred from the flat file to the SQL Server database, so that it can be used by the HR personnel at Tebisco Inc.

8 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 8 of 23 Solution 1.Identify a method to transfer from an external source into SQL Server 2.Perform data transfer. 3.Check whether the data has been transferred.

9 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 9 of 23 Identify a method to transfer from an external source into SQL Server Data transfer from an external source to an SQL Server database is called BCP IN. If the data is being transferred from the SQL Server to an external source outside SQL Server, then it is called BCP OUT. The external source is a flat file. BCP IN is also called importing data and BCP OUT is called exporting data.

10 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 10 of 23 Perform data transfer Action Start MS DOS Type the following at the command prompt : BCP Recruitment..College IN College.txt – SHRServer – Usa -Ppassword

11 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 11 of 23 Check whether the data has been transferred. Query the target table to see if the rows have been added.

12 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 12 of 23 Practice-Transferring Data From a Table to a Text File Problem Statement The contract recruiter information is required in the form of a text file so that it is usable by another software.

13 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 13 of 23 DTS DTS is a set of graphical tools and programmable objects with which you can extract, transform, and consolidate data from dissimilar tables in different locations into single or multiple locations. A DTS package contains a collection of DTS transformations, DTS tasks, connections, and workflow constraints.

14 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 14 of 23 DTS Tasks DTS Tasks are functions that are executed in a single step in a DTS package. Some common tasks are: Import and export data Transform Data Copy database objects Send and receive messages to and from other users and packages Execute a set of Transact-SQL statements or Microsoft ActiveX scripts against a data source

15 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 15 of 23 DTS Transformations Before the data arrives at the destination, some operations or one or more functions are applied to the data. This process is called data transformation. The source data is kept unchanged. Some of the common transformations are given below. Manipulate column data. Apply functions written as ActiveX scripts. Choose from among a number of transformations supplied with DTS. Write your own transformations as COM objects and apply those transformations against column data.

16 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 16 of 23 DTS Tools The following are the various tools provided by Microsoft SQL Server with which you can create, schedule, and execute DTS packages. DTS Export/Import Wizard DTS Designer DTS and SQL Enterprise Manager DTS Package Execution Utilities DTS Query Designer

17 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 17 of 23 Demonstration-Exporting Data From SQL Server to an External Source Problem Statement The data on campus recruitment is required for analysis. It is felt that analysis can be done easily using MS Excel. Hence, the data from the CampusRecruitment table is to be transferred to an MS Excel file.

18 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 18 of 23 Solution 1.Identify a method to transfer data from SQL Server to an MS Excel file. 2.Perform data transfer. 3.Check whether the data has been transferred.

19 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 19 of 23 Identify a method to transfer data from SQL Server to an MS Excel file. DTS Data Transformation Services (DTS) can be used to import and export data between multiple heterogeneous data sources and SQL Server. The external data sources include Visual Foxpro, MS Excel, Paradox, MS Access, dBase, and text files.

20 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 20 of 23 Perform data transfer. Action To export data from SQL Server to another data source, you need to use the DTS Export Wizard from the Enterprise Manager.

21 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 21 of 23 Check whether the data has been transferred. Open the file in MS Excel and match the content with that of the SQL Server table.

22 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 22 of 23 Practice-Exporting Data From SQL Server to an External Source Problem Statement The data on recruitment agencies is required for some analysis. The analysis to be done using MS Excel. Transfer the data from the HR database in SQL Server to MS Excel.

23 ©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 23 of 23 Summary In this lesson, you learned that: The bulk copy (BCP) program is a utility, which you can execute from the console or command prompt. You can use BCP for transferring data from SQL Server table to an external source and vice versa. Typically the external file is a flat file. Like BCP, the BULK INSERT statement can also be used to transfer data from a data file to a SQL Server table. DTS is a set of graphical tools and programmable objects with which you can extract, transform, and consolidate data from dissimilar tables in different locations into single or multiple locations. A DTS package contains a collection of DTS transformations, DTS tasks, connections, and workflow constraints. You can use DTS for transferring data from an external source to an SQL Server table and vice versa. Typically, the external sources are MS- Excel, Paradox, MS Access, dBase and text files.


Download ppt "©NIIT BCP and DTS Implementing Stored Procedures Lesson 2A / Slide 1 of 23 Objectives In this lesson, you will learn to: Perform bulk copy using the BCP."

Similar presentations


Ads by Google