可以看到:10000次插入使用事务提交只用时4.7秒,而不使用事务用时311秒,拼装成10000次insert语句的耗时7.3秒。这里面耗时7.3秒的,理论上,在数据库sql执行上也应该和使用事务差不多,这里的耗时主要是用作字符串的拼接上,客户端耗时比较多;
贴上测试程序代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data; using MySql.Web; using MySql.Data.MySqlClient; using System.Diagnostics; using System.Data; namespace mysqlDEMO01 { class Program { static void Main(string[] args) { testInsert(); Console.ReadLine(); } //使用安全防注入 参数使用@ ,安全插入。 public static void testInsert() { List<MySqlParameter> lmp = new List<MySqlParameter>(); lmp.Add(new MySqlParameter("@pname", "hello2")); lmp.Add(new MySqlParameter("@pwd", "1232")); string command = " insert into test.testtable(pname,pwd) value(@pname,@pwd); "; MySqlInstance.InsertData(command, lmp); List<MySqlParameter> lmp2 = new List<MySqlParameter>(); lmp2.Add(new MySqlParameter("@pname", "hello2")); lmp2.Add(new MySqlParameter("@pwd", "1232")); MySqlInstance.InsertDataNoTran(command, lmp2); test4(); } } }
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
更多Mysql内容来自木庄网络博客
标签:Mysql
相关阅读 >>
更多相关阅读请进入《mysql》频道 >>

数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。