Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Performing bulk import using the bcp command-line utility


This recipe will walk through the process of importing the contents of a CSV file to SQL Server using PowerShell and bcp.

Getting ready

To do a test import, let's first create a Person table similar to the Person.Person table from the AdventureWorks2014 database, with some slight modifications. We will create this in the Test schema, and we will remove some of the constraints and keep this table as simple and independent as we can.

If Test.Person does not yet exist in your environment, let's create it. Open up SQL Server Management Studio and run the following code:

CREATE SCHEMA [Test]
GO
CREATE TABLE [Test].[Person](
  [BusinessEntityID] [int] NOT NULL PRIMARY KEY,
  [PersonType] [nchar](2) NOT NULL,
  [NameStyle] [dbo].[NameStyle] NOT NULL,
  [Title] [nvarchar](8) NULL,
  [FirstName] [dbo].[Name] NOT NULL,
  [MiddleName] [dbo].[Name] NULL,
  [LastName] [dbo].[Name] NOT NULL,
  [Suffix] [nvarchar](10) NULL,
  [EmailPromotion] [int]...