首页 > 代码库 > 一些SQL整理
一些SQL整理
统计SQL执行时间和次数的语句:
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
查询所有表的数据量
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
清除LOG
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 (N‘dbname_Log‘ , 0,TRUNCATEONLY) GO
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。