Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2016-08-18
6
Medium Priority
?
463 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:Francois Koutchouk
[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 2000 total points
ID: 41761507
0
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 2000 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 2

Author Comment

by:Francois Koutchouk
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 2

Author Comment

by:Francois Koutchouk
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The following article is comprised of the pearls we have garnered deploying virtualization solutions since Virtual Server 2005 and subsequent 2008 RTM+ Hyper-V in standalone and clustered environments.
During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

636 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