search
HomeDatabaseMysql Tutorial读取SQL Server日志及代理日志

读取SQL Server日志及代理日志,最近闲的没事,为了以后的工作提高效率,其实是不想让自己的眼睛和手 太累。于是写了如下脚本 来解

最近闲的没事,为了以后的工作提高效率,,其实是不想让自己的眼睛和手 太累。于是写了如下脚本 来解放自己。  

---查看每个磁盘剩余空间大小(M)  
Exec master.dbo.xp_fixeddrives  
--或者  
declare @Fixed_tb table(Drive_NO char(1),Remainder_M bigint) 
INSERT INTO @Fixed_tb exec master.dbo.xp_fixeddrives 
select Drive_NO '驱动盘符',Remainder_M'剩余M',cast(((Remainder_M/1024)+0.001*(Remainder_M%1024))as dec(18,2))'剩余G' from @Fixed_tb 
GO  
 
-----SQL SERVER 日志   
 
declare @tmp table  (LogDate datetime,ProcessInfo varchar(32),Text nvarchar(max)) 
 
insert into @tmp 
EXEC master.dbo.xp_readerrorlog 0, 1, NULL, NULL, NULL, NULL, N'desc'---读取SQL Server 日志  
 
select * from @tmp where 1=1 
/* 
 一共有7个参数:  
 
1. 存档编号 
2. 日志类型(1为SQL Server日志,2为SQL Agent日志) 
3. 查询包含的字符串 
4. 查询包含的字符串 
5. LogDate开始时间 
6. 结果排序,按LogDate排序(可以为降序"Desc" Or 升序"Asc") 
7. 结果排序,按LogDate排序(可以为降序"Desc" Or 升序"Asc")  
 
在输入第5和第6个参数的时候,使用时间里包含有秒、毫秒时候,有时候查询速度非常慢,而且导致CPU占用率为100%。 
 
*/ 
 
 
--作业活动监视器 详细内容  
 
SELECT c.job_id,a.name,case when a.enabled =1 then '是' else '否' end '是否启用', 
 a.date_created '创建时间',a.date_modified '修改时间', 
 left(b.last_run_date,4)+'/'+SUBSTRING(convert(varchar(8),b.last_run_date),5,2)+'/'+right(b.last_run_date,2)+'  '+ 
 case when b.last_run_time=0 then '0:00:00'  
      when LEN(b.last_run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),b.last_run_time),1,1)+':'+RIGHT(b.last_run_time,2) 
      when LEN(b.last_run_time)=4 then '0:'+LEFT(b.last_run_time,2)+':'+RIGHT(b.last_run_time,2) 
      when len(b.last_run_time)=5 then left(b.last_run_time,1)+':'+SUBSTRING(convert(varchar(6),b.last_run_time),2,2)+':'+right(b.last_run_time,2) 
      else left(b.last_run_time,2)+':'+SUBSTRING(convert(varchar(6),b.last_run_time),3,2)+':'+right(b.last_run_time,2)end'上次运行时间', 
 left(c.next_run_date,4)+'/'+SUBSTRING(convert(varchar(8),c.next_run_date),5,2)+'/'+right(c.next_run_date,2)+'  '+ 
 case when c.next_run_time=0 then '0:00:00'  
      when LEN(c.next_run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),c.next_run_time),1,1)+':'+RIGHT(c.next_run_time,2) 
      when LEN(c.next_run_time)=4 then '0:'+LEFT(c.next_run_time,2)+':'+RIGHT(c.next_run_time,2) 
      when len(c.next_run_time)=5 then left(c.next_run_time,1)+':'+SUBSTRING(convert(varchar(6),c.next_run_time),2,2)+':'+right(c.next_run_time,2) 
      else left(c.next_run_time,2)+':'+SUBSTRING(convert(varchar(6),c.next_run_time),3,2)+':'+right(c.next_run_time,2)end '下次运行时间', 
  case   when substring(b.last_outcome_message,1,CHARINDEX('。', b.last_outcome_message)) is NULL then 
  '未知' else substring(b.last_outcome_message,1,CHARINDEX('。', b.last_outcome_message)) end '上次运行结果' 
 
FROM 
[msdb].[dbo].[sysjobs_view] a  
join    [msdb].[dbo].[sysjobservers] b 
on a.job_id =b.job_id  
join [msdb].[dbo].[sysjobschedules] c 
on a.job_id =c.job_id  
where a.category_id =0 or a.category_id =3 
 
----每个作业详细运行步骤及结果  
 
select a.name ,a.description,a.date_created,a.date_modified, 
  b.message,   
  left(b.run_date,4)+'/'+SUBSTRING(convert(varchar(8),b.run_date),5,2)+'/'+right(b.run_date,2)+'  '+ 
   case when b.run_time=0 then '0:00:00'  
    when LEN(b.run_time)=3 then '0:0'+SUBSTRING(convert(varchar(6),b.run_time),1,1)+':'+RIGHT(b.run_time,2) 
    when LEN(b.run_time)=4 then '0:'+LEFT(b.run_time,2)+':'+RIGHT(b.run_time,2) 
    when len(b.run_time)=5 then left(b.run_time,1)+':'+SUBSTRING(convert(varchar(6),b.run_time),2,2)+':'+right(b.run_time,2) 
    else left(b.run_time,2)+':'+SUBSTRING(convert(varchar(6),b.run_time),3,2)+':'+right(b.run_time,2)end'运行时间', 
    case when b.run_status=1 then '成功' else '失败' end '状态' 
 
 FROM [msdb].[dbo].[sysjobs_view] a ,[msdb].[dbo].[sysjobhistory] b 
 where a.job_id =b.job_id and (a.category_id =0 or a.category_id =3) 

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
microsoft sql server是什么软件microsoft sql server是什么软件Feb 28, 2023 pm 03:00 PM

microsoft sql server是Microsoft公司推出的关系型数据库管理系统,是一个全面的数据库平台,使用集成的商业智能(BI)工具提供了企业级的数据管理,具有使用方便可伸缩性好与相关软件集成程度高等优点。SQL Server数据库引擎为关系型数据和结构化数据提供了更安全可靠的存储功能,使用户可以构建和管理用于业务的高可用和高性能的数据应用程序。

SQL Server还是MySQL?最新研究揭秘最佳数据库选择。SQL Server还是MySQL?最新研究揭秘最佳数据库选择。Sep 08, 2023 pm 04:34 PM

SQLServer还是MySQL?最新研究揭秘最佳数据库选择近年来,随着互联网和大数据的快速发展,数据库的选择成为了企业和开发者们面临的一个重要问题。在众多数据库中,SQLServer和MySQL作为两个最为常见和广泛使用的关系型数据库,备受争议。那么,在SQLServer和MySQL之间,到底应该选择哪一个呢?最新的研究为我们揭示了这个问题。首先,让

PHP和SQL Server数据库开发PHP和SQL Server数据库开发Jun 20, 2023 pm 10:38 PM

随着互联网的普及,网站和应用程序的开发成为了许多企业和个人的主要业务。而PHP和SQLServer数据库则是其中非常重要的两个工具。PHP是一种服务器端脚本语言,可以用于开发动态网站;SQLServer是微软公司开发的关系型数据库管理系统,具有广泛的应用场景。在本文中,我们将讨论PHP和SQLServer的开发,以及它们的优缺点和应用方法。首先,让我们

如何使用PDO连接到Microsoft SQL Server数据库如何使用PDO连接到Microsoft SQL Server数据库Jul 29, 2023 pm 01:49 PM

如何使用PDO连接到MicrosoftSQLServer数据库介绍:PDO(PHPDataObjects)是PHP提供的一个访问数据库的统一接口。它提供了许多优点,比如实现了数据库的抽象层,可以方便地切换不同的数据库类型,而不需要修改大量的代码。本文将介绍如何使用PDO连接到MicrosoftSQLServer数据库,并提供一些相关代码示例。步骤

浅析PHP连接SQL Server的五种方法浅析PHP连接SQL Server的五种方法Mar 21, 2023 pm 04:32 PM

在Web开发中,PHP与MySQL的结合是非常常见的。但是,在某些情况下,我们需要连接其他类型的数据库,例如SQL Server。在本文中,我们将介绍使用PHP连接SQL Server的五种不同方法。

SQL Server与MySQL较量,如何选择最佳数据库方案?SQL Server与MySQL较量,如何选择最佳数据库方案?Sep 10, 2023 am 08:07 AM

随着互联网的不断发展,数据库的选择愈发重要。在众多的数据库中,SQLServer和MySQL是两个备受瞩目的选项。SQLServer是微软公司开发的关系型数据库管理系统,而MySQL则是一种开源的关系型数据库管理系统。那么在SQLServer和MySQL之间如何选择最佳的数据库方案呢?首先,我们可以从性能方面比较这两个数据库。SQLServer在处理

SQL Server与MySQL对比:哪个数据库更适合高可用性架构?SQL Server与MySQL对比:哪个数据库更适合高可用性架构?Sep 10, 2023 pm 01:39 PM

SQLServer与MySQL对比:哪个数据库更适合高可用性架构?在当今的数据驱动世界中,高可用性是构建可靠和稳定系统的必要条件之一。数据库作为数据存储和管理的核心组件,其高可用性对于企业的业务运转至关重要。在众多的数据库中,SQLServer和MySQL是常见的选择。那么在高可用性架构方面,究竟哪个数据库更适合呢?本文将对二者进行对比,并给出一些建议。

SQL Server和MySQL比较:哪个更适合大规模数据处理?SQL Server和MySQL比较:哪个更适合大规模数据处理?Sep 09, 2023 am 09:36 AM

SQLServer和MySQL是目前两个非常流行的关系型数据库管理系统(RDBMS)。它们都是用于存储和管理大规模数据的强大工具。然而,它们在处理大规模数据时有一些不同之处。本文将对SQLServer和MySQL进行比较,重点是它们在大规模数据处理方面的适用性。首先,让我们来了解一下SQLServer和MySQL的基本特点。SQLServer是由微软

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment