1、单击开始--程序--Microsoft SQL Server 2008--性能工具--SQL Server Profiler,如下图:


2、然后进入SqlServer Profiler 窗口:如图:


3、在工作窗口中弹出数据连接的窗口,输入数据连接的服务器和用户名密码,如图:


4、 输入完成后,单击连接按钮,弹出跟踪属性窗口,窗口中左边的“常规”选项卡是一个基本设置,一般使用默认的就OK了。右边的“事件选择”选项卡,用来设置要跟踪的事件有哪些,列表的事件可以一一选择,基本上Sql上有的事件都有,包括你用SQL Server Management Studio操作数据库的过程都可以跟踪的到,只要单击显示所有事件就可以进行全部事件的选择了。




5、在“事件选择”选项卡中还可以对统计的字段进行筛选,单击任意一个列标题可以查看列的说明,如下图:


6、上图依次说明为:
TextDate 依赖于跟踪中捕获的事件类的文本值;
ApplicationName 创建 SQL Server 连接的客户端应用程序的名称。此列由该应用程序传递的值填充,而不是由所显示的程序名填充的;
NTusername Windows 用户名。
LoginName 用户的登录名(SQL Server 安全登录或 Windows 登录凭据,格式为“域\用户名”)
CPU 事件使用的 CPU 时间(毫秒)。
Reads 由服务器代表事件读取逻辑磁盘的次数。
Writes 由服务器代表事件写入物理磁盘的次数。
Duration 事件占用的时间。尽管服务器以微秒计算持续时间,SQL Server Profiler 却能够以毫秒为单位显示该值,具体情况取决于“工具”>“选项”对话框中的设置
ClientProcessID 调用 SQL Server 的应用程序的进程 ID。
SPID SQL Server 为客户端的相关进程分配的服务器进程 ID。
StratTime 事件(如果可用)的启动时间。
EndTime 事件结束的时间。对指示事件开始的事件类(例如 SQL:BatchStarting 或 SP:Starting)将不填充此列。
BinaryData 依赖于跟踪中捕获的事件类的二进制值。


通过上面的图我们就可以清楚的跟踪到每一步操作是过程了。从窗口中还可以清楚的看到详细的sql语句写法,如果对Sql语句的写法有歧义或不明白的话就可以参考上面的,而且是时时的,在Sql里操作几下这里就会出现相应的Sql语句,这也是一个学习和提高的好工具,不仅仅是这样,我们还可以对其中的数据进行分析,查询,跟踪可以暂停,开始和停止操作,可以同时启动多个跟踪,同时跟踪不同的数据库和表,如果和Sql的数据库引擎优化顾问配合使用的话就更好了,可以分析出来你的Sql语句性能如果,而且还会告诉你怎么修改会更好。