以前都是好好的,现在记录多了后,用C#执行sql数据库的删除命令速度突然慢了好多。开始以为是数据库数据多了,一查只有20多万行,又怀疑是带宽的问题,就把数据库和程序放在一台电脑上,还是慢。后来直接在sql数据库里操作删除命令,竟然也是慢,这是怎么回事了。我的C#语句如下
string strsql = "delete from Tg where 日期='" + datDate.ToString("yyyyMMdd") + "' and name='" + fcer[i].strName + "' and 地点='" + fcer[i].strStation + "' and 时效='" + (j * 24).ToString("000") + "' and 时间='" + fcer[i].strSC + "'";
SqlCommand delcmd = new SqlCommand(strsql1, sqlcon);
delcmd.ExecuteNonQuery();
就是执行delcmd.ExecuteNonQuery()命令时,速度非常慢,符合条件的只有一条记录,但要删除这条记录要执行5、6秒钟甚至更长,有时候会长到断开连接...。执行其他语句如select、insert都挺快的,这是出了什么问题。
string strsql = "delete from Tg where 日期='" + datDate.ToString("yyyyMMdd") + "' and name='" + fcer[i].strName + "' and 地点='" + fcer[i].strStation + "' and 时效='" + (j * 24).ToString("000") + "' and 时间='" + fcer[i].strSC + "'";
SqlCommand delcmd = new SqlCommand(strsql1, sqlcon);
delcmd.ExecuteNonQuery();
就是执行delcmd.ExecuteNonQuery()命令时,速度非常慢,符合条件的只有一条记录,但要删除这条记录要执行5、6秒钟甚至更长,有时候会长到断开连接...。执行其他语句如select、insert都挺快的,这是出了什么问题。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货