You are on page 1of 20

7/23/2019 Print content

Administering Microsoft SQL Server 2012 Databases

Import and Export Data

Introduction
Data Import and Export
Summary

Introduction
The Import and Export Data module provides you with the instruction and server
hardware to develop your hands on skills in the defined topics. This module includes the
following exercises:

Data Import and Export

Lab Diagram

During your session you will have access to the following lab configuration. Depending
on the exercises you may or may not use all of the devices, but they are shown here in the
layout to get an overall understanding of the topology of the lab.

Connecting to your lab

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 1/20
7/23/2019 Print content

In this module you will be working on the following equipment to carry out the steps
defined in each exercise.

PLABSQL01 (SQL Server 1)

To start, simply choose a device and click Power on. In some cases, the devices may
power on automatically.

For further information and technical support, please see our Help and Support
page.

Copyright Notice
This document and its content is copyright of Practice-IT - © Practice-IT 2014. All rights reserved. Any
redistribution or reproduction of part or all of the contents in any form is prohibited other than the
following:
1) You may print or download to a local hard disk extracts for your personal and non-commercial use
only.
2) You may copy the content to individual third parties for their personal use, but only if you
acknowledge the website as the source of the material. You may not, except with our express written
permission, distribute or commercially exploit the content. Nor may you transmit it or store it in any
other website or other form of electronic retrieval system.

Exercise 1 - Data Import and Export


In this exercise, you will perform the tasks required to import and export data. To better
understand thesetasks, please refer to your course material or visit
http://msdn.microsoft.com/en-us/library/ms140052.aspx to gain an understanding of
this topic.

In this exercise, you will learn the following about Microsoft SQL Server 2012:

Transferring data
Performing bulk copy
Performing bulk insert

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 2/20
7/23/2019 Print content

Transferring Data

The Import and Export Wizard, or DTAWizard.exe, is a component that belongs to SQL
Server Integration Services. When you use the Import and Export Wizard, you can
import or export data from the following sources:

.NET Framework Data Provider for SQLServer


Flat File Source
Microsoft Access
Microsoft Excel
Microsoft OLE DB Provider for Analysis Services 11.0
Microsoft OLE DB Provider for Oracle
Microsoft OLE DB Provider for SQL Server
SQL Server Native Client 11.0

To transfer data, perform the following steps:

Step 1
Ensure you have powered on the required devices and Connect to PLABSQL01.

Click Start, select All Programs, select Microsoft SQL Server 2012, and then select
Import and Export Data (64-bit).

The SQL Server Import and ExportWizardwizard is displayed. Click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 3/20
7/23/2019 Print content

Keep the default settings for all fields except Database.

Click the Database drop-down list, select AdventureWorks2012, and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 4/20
7/23/2019 Print content

On the Choose a Destination screen, click New.

The Create Database dialog box is displayed.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 5/20
7/23/2019 Print content

Enter PLAB in the Name field and click OK.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 6/20
7/23/2019 Print content

Note that PLAB is now selected as the Database. Click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 7/20
7/23/2019 Print content

On the Specify Table copy or Query screen, keep the default selection of Copy data
from one or more tables or views and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 8/20
7/23/2019 Print content

On the Select Source Tables and Views screen, select the checkbox before Source:
(local) and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 9/20
7/23/2019 Print content

On the Save and Run Package screen, Run immediately is selected by default. Click
Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 10/20
7/23/2019 Print content

On the Complete the Wizard screen, click Finish.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 11/20
7/23/2019 Print content

The Performing Operation screen is displayed.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 12/20
7/23/2019 Print content

Note that export and import operation may take some time.

After the export and import operation is complete, click Close.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 13/20
7/23/2019 Print content

Navigated back to the desktop.

Performing Bulk Copy

In SQL Server, the bcp utility can be used to perform bulk import or export data. You can
import data from a file or export data to a file from the database. If you have installed the
SQL Server Native Client feature, then you can use the bcp utility with the XML format
files. The bcputilty is run along with the SQL query to achieve the output.

To perform backup / restore based on proper strategies including backup redundancy,


perform the following steps:

Step 1
From PLABSQL01 open SQL Server Management Studio.

The Connect to Server dialog box is displayed.

Keep the default settings and click Connect.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 14/20
7/23/2019 Print content

Microsoft SQL Server Management Studio opens.

In Object Explorer, expand Databases, right-click


AdventureWorks2012,andselect New Query.

You can perform different operations using the bcp command.

To copy a specific column into a data file, run the following command in a new query
window:

bcp "SELECT Name FROM AdventureWorks.Sales.Currency"


queryoutCurrency.Name.dat -T -c

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 15/20
7/23/2019 Print content

To copy a specific row into a data file, run the following command in a new query
window:

bcp "SELECT * FROM AdventureWorks2012.Person.Person WHERE


FirstName='Jarrod' AND LastName='Rana' " queryout "Jarrod
Rana.dat" -T -c

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 16/20
7/23/2019 Print content

To create an XML file, run the following command in a new query window:

bcp AdventureWorks2012.Sales.Currency format nul -T -c -x -


f Currency.xml

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 17/20
7/23/2019 Print content

Performing Bulk Insert

You can use the BULK INSERT statement and then load data into a table. The BULK
INSERT statement imports the data from a file and then adds the data into the table.

To perform backup / restore based on proper strategies including backup redundancy,


perform the following steps:

Step 1
From Microsoft SQL Server Management Studio in Object Explorer, expand
Databases, right-click AdventureWorks2012,andselect New Query.

You can perform different operations using the BULK INSERT command.

To import data from a file, run the following command in a new query window:

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 18/20
7/23/2019 Print content

BULK INSERT AdventureWorks2012.Sales.SalesOrderDetail


FROM ‘c:\data\test.txt’
GO

Close the query window without saving and collapse the AdventureWorks2012 node in
Object Explorer.

Shutdown all virtual machines used in this lab, by using the power functions located in
the Tools bar before proceeding to the next module. Alternatively you can log out of the
lab platform.

Summary
In this exercise, you learnt the following about Microsoft SQL Server 2012:
https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 19/20
7/23/2019 Print content

Transferring data
Performing bulk copy
Performing bulk insert

Also try
Using the current lab setup, you can perform the following tasks at your own pace.

Exporting and importing data into a new database named PLAB-New


Using the bcp command without the -T option.Observe the result and figure out
what other parameters have to be used in case you do not use -T
Creating a new text file and then importing it into the Person.Address table.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 20/20

You might also like