Solved

Need to import a CSV file into an existing Azure SQL Server table

Posted on 2016-08-18
6
131 Views
Last Modified: 2016-10-13
I have Visual Studio Community 2015.
I have an existing table with the correct columns, matching in order and data type the CSV file...
I was expecting something like a right click, import.   Seems like such a basic functionality.
What do you recommend?
0
Comment
Question by:FKoutchouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 500 total points
ID: 41761507
0
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 500 total points
ID: 41761510
Or if you can run a query against the database table you could use a process like below - just adjust table name/definition and name/path to actual CSV file. You can test this on a local SQL as well prior to running it against live cloud DB table:


--IMPORT
CREATE TABLE MySample
(ID INT,
FirstName VARCHAR(40),
LastName VARCHAR(40),
BirthDate SMALLDATETIME)
GO

--Create CSV file in drive C: with name Sample-Output.csv.txt with following content. The location of the file is C:\Sample-Output.csv.txt
1,James,Smith,19750101
2,Meggie,Smith,19790122
3,Robert,Smith,20071101
4,Alex,Smith,20040202


--Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted.
BULK
INSERT MySample
FROM 'c:\Sample-Output.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM MySample
GO
--From here on you can do anything you want with data imported via T-SQL Ccommands

--Drop the table to clean up database.
--DROP TABLE MySample
GO
0
 
LVL 1

Author Comment

by:FKoutchouk
ID: 41761649
Whoops except I get
Msg 40526, Level 16, State 1, Line 8
'BULK' rowset provider not supported in this version of SQL Server when connected to my Azure SQL Server.
0
 
LVL 1

Author Comment

by:FKoutchouk
ID: 41761731
In SQLyog front-end to MySQL, I just right-click on my RDS instance, select the CSV file and done...
0
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 41762915
Right...arghhh...well in that case BCP is the one that can save you and you should run a command like:

bcp database_name.schema.table in C:\import.csv -c -U username @servername -S servername.database.windows.net -P password -t

I added -t syntax to specify that it was comma delimited assuming that is your CSV delimiter and for more switches please see BCP command.

https://azure.microsoft.com/en-us/blog/bcp-and-sql-azure/
https://azure.microsoft.com/en-us/documentation/articles/sql-data-warehouse-load-with-bcp/
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Or at least that’s the word according to a new blog from Tech Target on AWS’s new Managed Services (MS) offering. According to the blog, AWS is launching their AWS MS program to expedite the adoption of cloud by Fortune 1000 and Global 2000 companie…
Optimized for private cloud infrastructures and datacenters, Nano Server is minimalistic, yet super-efficient, OS for services such as Hyper-V and Hyper-V cluster. Learn how you can easily deploy Nano Server and unlock its power!
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question