刀片2万行到SQL Server快速

编程入门 行业动态 更新时间:2024-10-25 16:27:54
本文介绍了刀片2万行到SQL Server快速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不得不从一个文本文件中插入大约200万行。

和与插入我需要创建一些主表。

什么是插入这样一个大的数据集到SQL Server的最佳和快速的方式?

解决方案
  • 我认为它更好的阅读文本文件中的数据集的数据

  • 试用使用SqlBulkCopy - 的批量插入从C#应用

    SQL

    //连接到SQL 使用(SqlConnection的连接=         新的SqlConnection(CONNSTRING)) {     //确保使触发器     //更多的触发下一篇文章中     SqlBulkCopy的bulkCopy =         新SqlBulkCopy的         (         连接,         SqlBulkCopyOptions.TableLock |         SqlBulkCopyOptions.FireTriggers |         SqlBulkCopyOptions.UseInternalTransaction,         空值         );     //设置目标表名     bulkCopy.DestinationTableName = this.tableName;     connection.Open();     //写在dataTable的数据     bulkCopy.WriteToServer(dataTable的);     的Connection.close(); } //复位 this.dataTable.Clear();

  • 做的步骤1在顶部后

  • 从DataSet中创建XML
  • 传递XML数据库,做批量插入
  • 您可以查看这篇文章的细节:数据的批量插入使用C#的DataTable和SQL服务器的OpenXML功能

    但它不是200万的记录进行测试,它会做,但消耗内存的机器,你必须负载2万人次的纪录,并将其插入。

    I have to insert about 2 million rows from a text file.

    And with inserting I have to create some master tables.

    What is the best and fast way to insert such a large set of data into SQL Server?

    解决方案

  • I think its better you read data of text file in DataSet

  • Try out SqlBulkCopy - Bulk Insert into SQL from C# App

    // connect to SQL using (SqlConnection connection = new SqlConnection(connString)) { // make sure to enable triggers // more on triggers in next post SqlBulkCopy bulkCopy = new SqlBulkCopy ( connection, SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.UseInternalTransaction, null ); // set the destination table name bulkCopy.DestinationTableName = this.tableName; connection.Open(); // write the data in the "dataTable" bulkCopy.WriteToServer(dataTable); connection.Close(); } // reset this.dataTable.Clear();

  • or

    after doing step 1 at the top

  • Create XML from DataSet
  • Pass XML to database and do bulk insert
  • you can check this article for detail : Bulk Insertion of Data Using C# DataTable and SQL server OpenXML function

    But its not tested with 2 million record, it will do but consume memory on machine as you have to load 2 million record and insert it.

    更多推荐

    刀片2万行到SQL Server快速

    本文发布于:2023-10-30 08:02:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1542256.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:刀片   快速   SQL   万行到   Server

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!