How to import CSV file in SQL server 2008?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
5
down vote

favorite
3












I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand
    Nov 5 at 16:00

















up vote
5
down vote

favorite
3












I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand
    Nov 5 at 16:00













up vote
5
down vote

favorite
3









up vote
5
down vote

favorite
3






3





I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.










share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to import a CSV file in SQL Server 2008. BULK INSERT is a way to go but it is applicable for CSV from SQL Server 2014 onwards.



What would be an alternative way to achieve this goal?



Any thoughts/ideas much appreciated.







sql-server sql-server-2008 import csv






share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 5 at 15:39









LowlyDBA

6,66352241




6,66352241






New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 5 at 15:20









T.H.

755




755




New contributor




T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






T.H. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand
    Nov 5 at 16:00














  • 1




    Actually FORMAT='CSV' is 2017+ (14 is the major version number).
    – Aaron Bertrand
    Nov 5 at 16:00








1




1




Actually FORMAT='CSV' is 2017+ (14 is the major version number).
– Aaron Bertrand
Nov 5 at 16:00




Actually FORMAT='CSV' is 2017+ (14 is the major version number).
– Aaron Bertrand
Nov 5 at 16:00










2 Answers
2






active

oldest

votes

















up vote
9
down vote



accepted










SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



file.csv contains:



foo,bar,1
blat,splunge,2


Then we do this:



CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

BULK INSERT #foo FROM 'c:tempfile.csv'
WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

SELECT * FROM #foo;


Results:



a        b        c
-------- -------- ----
foo bar 1
blat splunge 2





share|improve this answer




























    up vote
    2
    down vote













    Following link



    https://support.discountasp.net/kb/a1179/how-to-import-a-csv-file-into-a-database-using-sql-server-management-studio.aspx



    enter image description here



    If you problem then next link follow
    I hope solve your problem



    https://host4asp.net/import-csv-file-using-sql-server-management-studio/






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "182"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });






      T.H. is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f221817%2fhow-to-import-csv-file-in-sql-server-2008%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      9
      down vote



      accepted










      SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



      file.csv contains:



      foo,bar,1
      blat,splunge,2


      Then we do this:



      CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

      BULK INSERT #foo FROM 'c:tempfile.csv'
      WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

      SELECT * FROM #foo;


      Results:



      a        b        c
      -------- -------- ----
      foo bar 1
      blat splunge 2





      share|improve this answer

























        up vote
        9
        down vote



        accepted










        SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



        file.csv contains:



        foo,bar,1
        blat,splunge,2


        Then we do this:



        CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

        BULK INSERT #foo FROM 'c:tempfile.csv'
        WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

        SELECT * FROM #foo;


        Results:



        a        b        c
        -------- -------- ----
        foo bar 1
        blat splunge 2





        share|improve this answer























          up vote
          9
          down vote



          accepted







          up vote
          9
          down vote



          accepted






          SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



          file.csv contains:



          foo,bar,1
          blat,splunge,2


          Then we do this:



          CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

          BULK INSERT #foo FROM 'c:tempfile.csv'
          WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

          SELECT * FROM #foo;


          Results:



          a        b        c
          -------- -------- ----
          foo bar 1
          blat splunge 2





          share|improve this answer












          SQL Server has always supported bulk inserting from CSV files, you just have to specify field/row terminators.



          file.csv contains:



          foo,bar,1
          blat,splunge,2


          Then we do this:



          CREATE TABLE #foo(a varchar(32), b varchar(32), c int);

          BULK INSERT #foo FROM 'c:tempfile.csv'
          WITH (ROWTERMINATOR = 'n', FIELDTERMINATOR = ',');

          SELECT * FROM #foo;


          Results:



          a        b        c
          -------- -------- ----
          foo bar 1
          blat splunge 2






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 5 at 15:58









          Aaron Bertrand

          148k18279476




          148k18279476
























              up vote
              2
              down vote













              Following link



              https://support.discountasp.net/kb/a1179/how-to-import-a-csv-file-into-a-database-using-sql-server-management-studio.aspx



              enter image description here



              If you problem then next link follow
              I hope solve your problem



              https://host4asp.net/import-csv-file-using-sql-server-management-studio/






              share|improve this answer

























                up vote
                2
                down vote













                Following link



                https://support.discountasp.net/kb/a1179/how-to-import-a-csv-file-into-a-database-using-sql-server-management-studio.aspx



                enter image description here



                If you problem then next link follow
                I hope solve your problem



                https://host4asp.net/import-csv-file-using-sql-server-management-studio/






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Following link



                  https://support.discountasp.net/kb/a1179/how-to-import-a-csv-file-into-a-database-using-sql-server-management-studio.aspx



                  enter image description here



                  If you problem then next link follow
                  I hope solve your problem



                  https://host4asp.net/import-csv-file-using-sql-server-management-studio/






                  share|improve this answer












                  Following link



                  https://support.discountasp.net/kb/a1179/how-to-import-a-csv-file-into-a-database-using-sql-server-management-studio.aspx



                  enter image description here



                  If you problem then next link follow
                  I hope solve your problem



                  https://host4asp.net/import-csv-file-using-sql-server-management-studio/







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 5 at 17:38









                  Mahfuz Morshed

                  1191210




                  1191210






















                      T.H. is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      T.H. is a new contributor. Be nice, and check out our Code of Conduct.













                      T.H. is a new contributor. Be nice, and check out our Code of Conduct.












                      T.H. is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f221817%2fhow-to-import-csv-file-in-sql-server-2008%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini