如何计算MS SQL语句执行的时间还有c#
MSSQL:
declare @begin datetime
declare @End datetime
set @begin=getdate()
--执行的语句写在这里
set @End=getdate()
select datediff(millisecond,@begin,@End) as 执行的时间
--millisecond表示毫秒 如果看秒可以使用ss
C#:
很多时候,我们对自己的程序的瓶颈不是很清楚。如一个本地类和一个webservice之间的调用到底是有多大的区别。页面整个的执行时间怎么样监控。程序是在那个地方化的时间最长。现在我就把.NET2.0以后的监控方法说下。其实很简单,只要在System.Diagnostics 中就有一个可以直接使用的类 --Stopwatch。不多说了。将代码贴出来。
protected void Page_Load(object sender, EventArgs e)
{
Stopwatch watch = new Stopwatch(); //实例化一个监控对象
watch.Start(); //开始监控业务逻辑
string a = null;
for (int i = 0; i < 10000; i++)
{
a = i.ToString();
}
Thread.Sleep(10); //将线程延迟10毫秒。一个多这样的测试,多要使用到线程方面
watch.Stop(); //结束监控
Response.Write(watch.ElapsedMilliseconds); //输出计时结果,单位:毫秒
}
相关文档:
随机读取若干条记录,测试过
Access语法:SELECT top 10 * from 表名 ORDER BY Rnd(id)
Sql server:select top n * from 表名 order by newid()
mysql select * from 表名 Order By rand() Limit n
说明:选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 or ......
declare @tmp table
(
id int identity(1,1),
TableName varchar(100),
Column_name varchar(100),
Type varchar(50),
Lenght int,
Scale int,
Nullable varchar(1),
Defaults varchar(4000),
PrimaryKey varchar(1)
)
select iid = identity(int,1,1), * into #a from SysObjects where xtype = 'U'
declare ......
号称xmlhelper的一个类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
namespace WebApplication2
{
/// <summary>
/// XMLHelper XML文档操作管理器
/// </summary>
public class XMLHelper
{
public X ......
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREATE DATABASE database-name
2、说明:删除数据库 ......