使用lazarus改善ms sql插入性能

编程入门 行业动态 更新时间:2024-10-26 14:36:49
本文介绍了使用lazarus改善ms sql插入性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的带有3个数据字段的插入语句. 不是主键且不会自动递增的Tag_ID, 一个时间戳,该时间戳将一个简单的DateTime Now保存为一个字符串,一个float值包含一个简单的devide计算.

sql服务器实际上是本地的,但是稍后它将在不在本地网络中的另一台计算机上.现在,我得到10.000个条目的时间为25.8秒.

我的代码如下:

procedure TForm1.testMssql(Datensaetze: integer); var i: integer; before,after,result: real; begin before := GetTickCount; for i:= 0 to Datensaetze do begin try query.DataBase := conn; query.UsePrimaryKeyAsKey:=false; query.SQL.Text := 'insert into speedTest(TagID,timestamp,Value) values(:tag_id,:timestamp, :value)'; query.Params.ParamByName('tag_id').AsInteger := i ; query.Params.ParamByName('timestamp').AsString := DateTimeToStr(Now); query.Params.ParamByName('value').AsFloat := ((i*2) / 55); query.ExecSQL; SQLTransaction1.Commit; except on E: Exception do ShowMessage(E.Message); end; end; after := GetTickCount; result := (after - before)/1000; Memo1.Text := FloatToStr(result); end;

解决方案

批量插入

msdn.microsoft/de-de/library/ms188365.aspx

i have a simple insert statement with 3 datafields. A Tag_ID which is not the primary key and not auto increment, a timestamp which saves an easy DateTime Now as a string and a float value which contains a simple devide calculation.

the sql server is actually local but later it will be on another machine not in the local network. Now i get 25,8 sec for 10.000 entries.. how can i improve this?

my code looks like this:

procedure TForm1.testMssql(Datensaetze: integer); var i: integer; before,after,result: real; begin before := GetTickCount; for i:= 0 to Datensaetze do begin try query.DataBase := conn; query.UsePrimaryKeyAsKey:=false; query.SQL.Text := 'insert into speedTest(TagID,timestamp,Value) values(:tag_id,:timestamp, :value)'; query.Params.ParamByName('tag_id').AsInteger := i ; query.Params.ParamByName('timestamp').AsString := DateTimeToStr(Now); query.Params.ParamByName('value').AsFloat := ((i*2) / 55); query.ExecSQL; SQLTransaction1.Commit; except on E: Exception do ShowMessage(E.Message); end; end; after := GetTickCount; result := (after - before)/1000; Memo1.Text := FloatToStr(result); end;

解决方案

Bulk Insert

msdn.microsoft/de-de/library/ms188365.aspx

更多推荐

使用lazarus改善ms sql插入性能

本文发布于:2023-10-26 10:05:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:性能   lazarus   ms   sql

发布评论

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

>www.elefans.com

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