因为要监视数据库的使用,需要每天查看并导出整个库的报表:性能-对象执行统计信息报表。
想问一下各位大牛,如何使sql每日自动生成报表并导出到某文件夹?
环境:windows2008r2+sql 2012
sql sqlserver 报表
------解决方案--------------------
自己写代码做吧,运行一下报表自己用Profiler Trace抓一下运行的语句,然后建立一个JOB运行这些语句倒入到Excel就可以了。
如果你有SSRS的更好做,做一个订阅到共享文件夹就可以。
------解决方案--------------------
写脚本也不行,除非你能知道那个报表所用的SSIS包,我说的脚本是通过DMO,查询出于报表相同的数据,然后用其他技术如BCP导出成文件
------解决方案--------------------
抓出这东西出来
exec sp_executesql @stmt=N'--object execution statistics
begin try
declare @cnt int;
declare @record_count int;
declare @dbid int;
declare @objectid int;
declare @cmd nvarchar(MAX);
declare @grand_total_worker_time float ;
declare @grand_total_IO float ;
declare @sql_handle_convert_table table(
row_id int identity
, t_sql_handle varbinary(64)
, t_display_option varchar(140) collate database_default
, t_display_optionIO varchar(140) collate database_default
, t_sql_handle_text varchar(140) collate database_default
, t_SPRank int
, t_dbid int
, t_objectid int
, t_SQLStatement varchar(max) collate database_default
, t_execution_count int
, t_plan_generation_num int
, t_last_execution_time datetime
, t_avg_worker_time float
, t_total_worker_time float
, t_last_worker_time float
, t_min_worker_time float
, t_max_worker_time float
, t_avg_logical_reads float
, t_total_logical_reads bigint
, t_last_logical_reads bigint
, t_min_logical_reads bigint
, t_max_logical_reads bigint
, t_avg_logical_writes float
, t_total_logical_writes bigint
, t_last_logical_writes bigint
, t_min_logical_writes bigint
, t_max_logical_writes bigint
, t_avg_logical_IO float
, t_total_logical_IO bigint
, t_last_logical_IO bigint
, t_min_logical_IO bigint
, t_max_logical_IO bigint
);
declare @objects table (
obj_rank int
, total_cpu bigint
, total_logical_reads bigint
, total_logical_writes bigint
, total_logical_io bigint
, avg_cpu bigint
, avg_reads bigint
, avg_writes bigint
, avg_io bigint
, cpu_rank int
, total_cpu_rank int
, logical_read_rank int
, logical_write_rank int
, logical_io_rank int
);
declare @object_name table (
dbId int
, objectId int
, dbName sysname collate database_default null