码迷,mamicode.com
首页 > 数据库 > 详细

一些SQL整理

时间:2014-04-28 11:14:38      阅读:640      评论:0      收藏:0      [点我收藏+]

标签:des   com   http   class   blog   style   div   code   img   java   javascript   

统计SQL执行时间和次数的语句:

mamicode.com,码迷
SELECT top 50
qt.text AS SQL_text ,
SUM(qs.total_worker_time) AS total_cpu_time,
SUM(qs.execution_count) AS total_execution_count,
SUM(qs.total_worker_time)/SUM(qs.execution_count) AS avg_cpu_time,
COUNT(*) AS number_of_statements
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt
GROUP BY qt.text
ORDER BY avg_cpu_time DESC --统计总的CPU时间 total_cpu_time
mamicode.com,码迷

查询所有表的数据量

mamicode.com,码迷
SELECT   a.name, b.rows
FROM      sysobjects AS a INNER JOIN
                 sysindexes AS b ON a.id = b.id
WHERE   (a.type = u) AND (b.indid IN (0, 1))
ORDER BY b.rows DESC
mamicode.com,码迷

清除LOG

mamicode.com,码迷
USE [master]
GO
ALTER DATABASE dbname SET RECOVERY SIMPLE WITH NO_WAIT
GO
ALTER DATABASE dbname SET RECOVERY SIMPLE
GO
USE dbname 
GO
DBCC SHRINKFILE (Ndbname_Log , 0,TRUNCATEONLY)
GO
mamicode.com,码迷

 

一些SQL整理,码迷,mamicode.com

一些SQL整理

标签:des   com   http   class   blog   style   div   code   img   java   javascript   

原文地址:http://www.cnblogs.com/relax/p/3695618.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!