zoukankan      html  css  js  c++  java
  • SQL Server使用Bulk Insert把一个文本导入到数据库http://www.wangchao.net.cn/it/detail_59013.html

    This is very common request recently – How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? Let us see the solution in quick steps.
      CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values.
      Create TestTable
      USE TestData
      GO
      CREATE TABLE CSVTest
      (ID INT,
      FirstName VARCHAR(40),
      LastName VARCHAR(40),
      BirthDate SMALLDATETIME)
      GO
      Create CSV file in drive C: with name csvtest.txt with following content. The location of the file is C:\csvtest.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 CSVTest
      FROM 'c:\csvtest.txt'
      WITH
      (
      FIELDTERMINATOR = ',',
      ROWTERMINATOR = '\n'
      )
      GO
      --Check the content of the table.
      SELECT *
      FROM CSVTest
      GO
      --Drop the table to clean up database.
      SELECT *
      FROM CSVTest
      GO
  • 相关阅读:
    DataGridView单元格内容自动匹配下拉显示
    C#中datagridviewz中SelectionMode的四个属性的含义
    Visual Studio效率神器——超级扩展ReSharper安装和破解
    vue优化(1) vuecli3/4 【图片压缩 】||【文件压缩】
    DownValues, UpValues, SubValues, 和OwnValues之间的区别?
    Leonid Shifrin 的书
    python newbie——蒙特卡罗法计算圆周率
    python newbie——PE No.1
    指尖上的数学
    瞎猫碰到死耗子
  • 原文地址:https://www.cnblogs.com/si812cn/p/1653495.html
Copyright © 2011-2022 走看看