Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Operations
Administration
 Bulk Exporting Data from or Bulk Im...
Other versions are also available for the following:
SQL Server 2008 Books Online (August 2008)
Bulk Exporting Data from or Bulk Importing Data to a View

You can bulk export data from any view by using a bcp command.

You can bulk import data into a view as follows:

  • Nonpartitioned views
    You can bulk import data into a nonpartitioned view by using a bcp command, a BULK INSERT statement, or an INSERT ... SELECT * FROM OPENROWSET(BULK...) statement.
  • Partitioned views
    You can bulk import data into a partitioned view by using the bcp command.
    Bulk importing into a partitioned view is unsupported by the BULK INSERT and INSERT ... SELECT * FROM OPENROWSET(BULK...) statements. However, you can insert multiple rows into a partitioned view by using an INSERT Transact-SQL statement.

All bulk-import operations meet the rules for inserting data into a view. For information about those rules, see Modifying Data Through a View.

ms187086.note(en-us,SQL.100).gifImportant:
The treatment of default values by any bulk-import operation depends on which bulk-import command or statement was used. For more information, see Keeping Nulls or Using Default Values During Bulk Import.

The following example uses a view of the HumanResources.DepartmentView table of the AdventureWorks sample database. From a query tool, such as Microsoft SQL Server Management Studio Query Editor, execute:

CREATE VIEW DepartmentView AS 
    SELECT DepartmentID, Name, GroupName 
    FROM HumanResources.Department;
GO

The following command bulk exports the data from the DepartmentView view into the DepartmentView.txt data file. At the Microsoft Windows command prompt, enter:

bcp AdventureWorks..DepartmentView out DepartmentView.txt -c -T

To delete this sample view, execute the following Transact-SQL statement:

DROP VIEW DepartmentView;
GO
ms187086.note(en-us,SQL.100).gifNote:
For an example of using a view in a BULK INSERT command, see Using a Format File to Skip a Table Column.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker