1 / 23

SQL 710

Week 5 – Chap. 5 Data Transfer. DBAs often must transfer data to and from text files, Excel spreadsheets, Access, Oracle or other SQL Server databases This process of transferring data is called migration Can be performed using a variety of methods. SQL 710.

lark
Download Presentation

SQL 710

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 5 – Chap. 5 Data Transfer • DBAs often must transfer data to and from text files, Excel spreadsheets, Access, Oracle or other SQL Server databases • This process of transferring data is called migration • Can be performed using a variety of methods SQL 710

  2. SQL Server’s Data Migration Tools • Data Transformation Services (DTS) • Bulk Copy Program(BCP) • Transact-SQL Bulk Insert Statement • Transact-SQL Select Into Statement SQL 710

  3. Data Transformation Services(DTS) • Most common method for data transfer • Easy to use wizard (Start  SQL Server  Import and Export Data) • DTS allows changes to data (transformation) while transferring data • Transfer of data to : Export • Transfer of data from : Import • Can import or export data to / from many sources (Excel, Oracle, SQL Server, Access) • Migration steps can be saved by DTS as a package and rerun later SQL 710

  4. DTS Transformation of Data • Mapping Data Types • You can specify how data is formatted between source and destination • You can specify how data is modified between source and destination • Integrating and Consolidating data • You can combine data • You can summarize data vertically and horizontally SQL 710

  5. DTS Packages • A set of DTS migration steps can be stored as a package • Packages can be saved to Database files or even in Microsoft Repository Feature • Packages consist of: • Connections to Data Sources and Destinations • Tasks – Commands to transfer data, edit data, … • Workflow – Precedence constraints for tasks SQL 710

  6. DTS Package: Connections SQL 710 Connection is between Source and Destination Data.

  7. DTS Package: Tasks • A Task is a unit of work • A Task could: • Execute a Transact SQL Statement • Execute a Script • Launch an external application • Copy SQL Server objects • Execute and retrieve results from a DTS Package SQL 710

  8. DTS Package : Workflow • Workflow links tasks • Workflow constraints coordinate flow of control and execution of steps in the DTS Package by precedence: SQL 710

  9. Workflow Order of Execution SQL 710

  10. Workflow Steps Priority By default all threads have the same priority. But you can change default priority for a step to: • Idle • Normal • High SQL 710

  11. Package Scheduling, Execution • Ways to execute a DTS Package: • Use SQL Enterprise Manager • Use dtsrun command prompt utility • Ways to Schedule a DTS Package: • Use DTS import/export wizard when saving to the msdb database • Use SQL Server Enterprise Manager when you use dtsrun command prompt utility. SQL 710

  12. DTS Designer DTS Designer allows experienced Database Administrators to import and export data, transform data and define complex workflows for heterogeneous data from multiple sources SQL 710

  13. DTS Object Transfer The Copy SQL Server Object task in both the DTS Import/Export Wizard and in DTS Designer allows easy transfer of database objects between SQL Server Databases. Objects to be transferred can include tables, views, stored procedures, defaults, rules, user-defined data types, logins, users, roles and constraints You can transfer all objects in a database or only a subset using this task. SQL 710

  14. Bulk Copy Program(BCP) • Bulk Copy Program is performed from O/S command prompt • Allows import or export of data from/to a text file or a binary file • The data migrated can be a table or a SQL query result. • BCP can bypass transaction log files, which improves speed but can compromise recovery • Always backup database before and after BCP operation SQL 710

  15. BCP (ctd) • BCP can create a format file to manipulate data • BCP is normally an automated process SQL 710

  16. BCP Export Example SQL 710

  17. BCP Import Example SQL 710

  18. BULK INSERT • A Transact-SQL command that can read a text file or native SQL Server file into an existing table or view • Can also use a format file (as BCP utility can) • Commands can be saved to a script • Scripts can be automated by using osql commands SQL 710

  19. BULK INSERT (ctd) • Fastest method of data transfer, because a session doesn’t have to be started for each data transfer • Database should be backed up after this operation • Used for copying operations in which performance is the most important consideration • Can’t transform data using this method SQL 710

  20. BULK INSERT Example USE pubs GO TRUNCATE TABLE authors2 GO BULK INSERT authors2 from "c:\temp\authors2.csv" GO SELECT * FROM authors2 GO SQL 710

  21. SELECT INTO • SELECT INTO statement copies data from one table to another • Tables can be on the same SQL Server or linked SQL servers or on different types of servers using distributed queries • SELECT INTO operates just like Bulk Insert except it can’t read from an external file • SELECT INTO can also create the destination table automatically before copying the data SQL 710

  22. SELECT INTO - EXAMPLE USE pubs GO DROP TABLE authors2 GO SELECT * INTO authors2 from authors GO SELECT * FROM authors2 GO SQL 710

  23. Lab Exercises • Export data using Enterprise Manager • Import data using Enterprise Manager • Truncate table from command line • Create Export text file from command line • Import data from command line • Bulk Insert • Select Into • Schedule a Package SQL 710

More Related