?????????????????????4?????????些?????DBA????????????????CPU??煤??????SQL???????????????????????????????????
?????????泻??????????????????????????????????????????????????
???????????1.????????sql???????????????
????????????????????SQL??????????????????????????????????????????????貌??????貌????????????榉�????????????????????????SQL?????????貌???????????????????榉�????????SQL??????OK
???????????2.????????????????????????????????????????
????????????????????????????????????????????写??????????????????眉????????????写????榉�??????????????????????????????sql??????????SqlParameter????????SqlDbType??size????????????????????写?????泻???????????????????????????????????泄????????泄????胁??????????????????????????????????????????????????????????????????????????????????????????MSDN????????未??size?????????????Size?????dbType??????????????小??????????????????????小?????SqlDbType??????????????????????????????????????????????????绱�??????????"username"????size??8??"username1"????size??9????????????size?????????????????????????????size?????????????????????屑???????????????????????sql??????????????渭???屑????????????????????
???????????????????
????????????????

????DBCC FREEPROCCACHE
???????username?????????????????????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username???????????????
//???????(@UserName varchar(8))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar) { Value = "username" });
comm.ExecuteNonQuery();
}
???????username1?????????????????????????
????????using (SqlConnection conn = new SqlConnection(connectionString))
????????{
????????conn.Open();
????????SqlCommand comm = new SqlCommand();
????????comm.Connection = conn;
????????comm.CommandText = "select * from Users where UserName=@UserName";
????????//??? username1???????????????
????????//???????(@UserName varchar(9))select * from Users where UserName=@UserName
????????comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar) { Value = "username1" });
????????comm.ExecuteNonQuery();
????????}
???????username??????????????50???????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username??????????????50
//???????(@UserName varchar(50))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar??50) { Value = "username" });
comm.ExecuteNonQuery();
}
???username1??????????????50???????????
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = "select * from Users where UserName=@UserName";
//??? username1??????????????50
//???????(@UserName varchar(50))select * from Users where UserName=@UserName
comm.Parameters.Add(new SqlParameter("@UserName"?? SqlDbType.VarChar??50) { Value = "username1" });
comm.ExecuteNonQuery();
}