由于网站的需要,要把数据库从access 转成sql server.之前我现做了一下简易的测试比较.由于手头没有大量的数据,我就以5000来条记录做测试,循环填充dataset,部分代码如下:
//SQL 与 Access 查询比较测试
//DateTime sta = DateTime.Now;
//DataSet ds = new DataSet();
//SqlDataAdapter a = new SqlDataAdapter("select * from [new]", Conn.getConn());
//for (int j = 0; j < 10; j++)
//{
// a.Fill(ds, "news");
//}
//a.Dispose();
//object now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("ds(SQL)的记录数是:" + ds.Tables["new"].Rows.Count + "。查询时间是:" + now.ToString());
//ds.Dispose();
//sta = DateTime.Now;
//ds = new DataSet();
//OleDbDataAdapter ab = new OleDbDataAdapter("select * from [new]", Conn.getConnAccess());
//for (int j = 0; j < 10; j++)
//{
// ab.Fill(ds, "news");
//}
//ab.Dispose();
//now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("ds(Access)的记录数是:" + ds.Tables["new"].Rows.Count + "。查询时间是:" + now.ToString());
//ds.Dispose();
//SQL 与 Access 查询比较测试结束
//SQL 与 Access 写数据比较测试
//DateTime sta = DateTime.Now;
//SqlConnection conn = Conn.getConn();
//SqlCommand cmd = new SqlCommand("insert into [test] (no) values ('1')", conn);
//conn.Open();
//for (int j = 0; j < 20000; j++)
//{
// cmd.ExecuteNonQuery();
//}
//object now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("(SQL)的记录数是:5000。写数据的时间是:" + now.ToString());
//cmd.CommandText = "delete from [test]";
//cmd.ExecuteNonQuery();
//cmd.Dispose();
//conn.Close();
//sta = DateTime.Now;
//OleDbConnection conna = Conn.getConnAccess();
//OleDbCommand cmda = new OleDbCommand("INSERT INTO test ([no]) values (1)", conna);
//conna.Open();
//for (int j = 0; j < 20000; j++)
//{
// cmda.ExecuteNonQuery();
//}
//now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("(Access)的记录数是:5000。写数据的时间是:" + now.ToString());
//cmda.CommandText = "delete from [test]";
//cmda.ExecuteNonQuery();
//cmda.Dispose();
//conna.Close();
//SQL 与 Access 写数据比较测试结束
//DateTime sta = DateTime.Now;
//DataSet ds = new DataSet();
//SqlDataAdapter a = new SqlDataAdapter("select * from [new]", Conn.getConn());
//for (int j = 0; j < 10; j++)
//{
// a.Fill(ds, "news");
//}
//a.Dispose();
//object now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("ds(SQL)的记录数是:" + ds.Tables["new"].Rows.Count + "。查询时间是:" + now.ToString());
//ds.Dispose();
//sta = DateTime.Now;
//ds = new DataSet();
//OleDbDataAdapter ab = new OleDbDataAdapter("select * from [new]", Conn.getConnAccess());
//for (int j = 0; j < 10; j++)
//{
// ab.Fill(ds, "news");
//}
//ab.Dispose();
//now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("ds(Access)的记录数是:" + ds.Tables["new"].Rows.Count + "。查询时间是:" + now.ToString());
//ds.Dispose();
//SQL 与 Access 查询比较测试结束
//SQL 与 Access 写数据比较测试
//DateTime sta = DateTime.Now;
//SqlConnection conn = Conn.getConn();
//SqlCommand cmd = new SqlCommand("insert into [test] (no) values ('1')", conn);
//conn.Open();
//for (int j = 0; j < 20000; j++)
//{
// cmd.ExecuteNonQuery();
//}
//object now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("(SQL)的记录数是:5000。写数据的时间是:" + now.ToString());
//cmd.CommandText = "delete from [test]";
//cmd.ExecuteNonQuery();
//cmd.Dispose();
//conn.Close();
//sta = DateTime.Now;
//OleDbConnection conna = Conn.getConnAccess();
//OleDbCommand cmda = new OleDbCommand("INSERT INTO test ([no]) values (1)", conna);
//conna.Open();
//for (int j = 0; j < 20000; j++)
//{
// cmda.ExecuteNonQuery();
//}
//now = Convert.ToDateTime(DateTime.Now) - sta;
//Response.Write("(Access)的记录数是:5000。写数据的时间是:" + now.ToString());
//cmda.CommandText = "delete from [test]";
//cmda.ExecuteNonQuery();
//cmda.Dispose();
//conna.Close();
//SQL 与 Access 写数据比较测试结束
我得电脑配置:P4 530 ,512M内存.5000条的数据量是:20M左右,大约填充了30万条在内存,执行时间表明:在读取数据上,SQL Server的效率大约是Access的5倍,写数据方面则是3倍,不过,这个测试很简易,很多因素没有处理,比如,读取数据时,我通过任务管理器观察,内存页面使用大约700M,这样,往缓存写数据会有不小影响,如果那个高人有很准确的比较,共享一下呀.