locked
T-Sql query to import data from CSV to sql Azure table. RRS feed

  • Question

  • Hi TEam,

    Can any one share T-Sql query to import data from CSV to sql Azure table.

    Wednesday, September 23, 2015 6:01 PM

Answers

  • I can use C# but doing with SQl is best appraoche.

    Why do you want to use T-SQL?  C# would be actually be the best approach since the app presumably has access to the CSV, unlike Azure SQL Database.  The code to import a CSV is fairly trivial and can more easily perform data validation in the process.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, September 26, 2015 2:12 PM
    Answerer
  • Hi ,

    Thanks for your inputs

    we can choose any table with two columns

    Example: A csv file with below column containing 1000 records

    username(Varchar(Max), password(Varchar(Max).

    anilkumar                        Hello123

    pituach                            hi123...

    OK, then please post one example instead of stories :-)

    * By the way, I agree with Dan. Since you gave us new information now, that you use C#. It seam like your best approach should be using C# code in this case. Using C# you can directly bulk insert the data from the file to Azure SQL Server, just like a local server. Once you connect to the database the use of it is the same.


    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

    Saturday, September 26, 2015 8:07 PM

All replies

  • Hi,

    Please check this blog regarding several options that you cab use:
    http://blogs.msdn.com/b/sqlcat/archive/2010/07/30/loading-data-to-sql-azure-the-fast-way.aspx


    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

    Wednesday, September 23, 2015 10:09 PM
  • Hello,

    On an on-premise SQL Server you could use the T-SQL command OPENROWSET (Transact-SQL) to load data; on SQL Azure this is not possible, you have to use a ETL tool like the Import/Export wizard


    Olaf Helper

    [ Blog] [ Xing] [ MVP]


    Thursday, September 24, 2015 7:29 AM
  • Hi Team,

    I found that import export is not possible . Can we get any TSQL query to read and write data from CSV to table using cursor e.t.c.

    I can use C# but doing with SQl is best appraoche.

    Appreciate if you could share any TSQL snnipet

    Friday, September 25, 2015 2:43 PM
  • Good day kumaranil,

    1. Have you checked the solutions that you got (The link that I posted you above and Olaf respond) ?!?

    I am asking since it is there!
    You got several solutions that fit your requirement

    If you do not know how to implement something then you should learn (or ask specific question if you have). We are here to help you learn :-)

    2. Unfortunately our Mind reading ability is too poor :-)
    We can not give you a query since we have no information regarding your table structure, or the data that you want to insert. Think about this for a sec... 
    If you need Code then you should provide us Code. Please post: 

    1) CREATE TABLE statements for the relevant tables
    2) CSV file that you want to import (only sample data! dont post several GB pls)
    3) Which version of SQL Server you are using



    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

    Friday, September 25, 2015 10:25 PM
  • Hi ,

    Thanks for your inputs

    we can choose any table with two columns

    Example: A csv file with below column containing 1000 records

    username(Varchar(Max), password(Varchar(Max).

    anilkumar                        Hello123

    pituach                            hi123...

    Saturday, September 26, 2015 11:52 AM
  • I can use C# but doing with SQl is best appraoche.

    Why do you want to use T-SQL?  C# would be actually be the best approach since the app presumably has access to the CSV, unlike Azure SQL Database.  The code to import a CSV is fairly trivial and can more easily perform data validation in the process.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, September 26, 2015 2:12 PM
    Answerer
  • Hi ,

    Thanks for your inputs

    we can choose any table with two columns

    Example: A csv file with below column containing 1000 records

    username(Varchar(Max), password(Varchar(Max).

    anilkumar                        Hello123

    pituach                            hi123...

    OK, then please post one example instead of stories :-)

    * By the way, I agree with Dan. Since you gave us new information now, that you use C#. It seam like your best approach should be using C# code in this case. Using C# you can directly bulk insert the data from the file to Azure SQL Server, just like a local server. Once you connect to the database the use of it is the same.


    signature   Ronen Ariely
     [Personal Site]    [Blog]    [Facebook]

    Saturday, September 26, 2015 8:07 PM