Skip to content

Instantly share code, notes, and snippets.

View tejaswidatla's full-sized avatar

Tejaswi Datla tejaswidatla

  • IBM
View GitHub Profile
DECLARE @Body VARCHAR(200), @Count VARCHAR(50), @endtime DATETIME;
SET @endtime = GETDATE();
DECLARE @starttime DATETIME;
SET @starttime = DATEADD(HH, -1, @endtime);
IF OBJECT_ID('tempdb..#LogEntries') IS NOT NULL
DROP TABLE #LogEntries;
CREATE TABLE #LogEntries
DECLARE @IntervalInHours TINYINT, @IsDBMailEnabled BIT, @MailSubject VARCHAR(100), @TableHTML VARCHAR(500)
SET @IntervalInHours = 1
 
IF EXISTS(
SELECT 1
FROM master.sys.databases db
WHERE DATEDIFF(HOUR, db.create_date, GETDATE()) <= @intervalInHours
AND db.name <> 'tempdb')
 
BEGIN 
DECLARE @Body VARCHAR(200), @Count VARCHAR(50), @endtime DATETIME;
SET @endtime = GETDATE();
DECLARE @starttime DATETIME;
SET @starttime = DATEADD(hh, -1, @endtime);
IF OBJECT_ID('tempdb..#LogEntries') IS NOT NULL
DROP TABLE #LogEntries;
CREATE TABLE #LogEntries
DECLARE @Body VARCHAR(200), @Count VARCHAR(50), @endtime DATETIME;
SET @endtime = GETDATE();
DECLARE @starttime DATETIME;
SET @starttime = DATEADD(hh, -1, @endtime);
IF OBJECT_ID('tempdb..#LogEntries') IS NOT NULL
DROP TABLE #LogEntries;
CREATE TABLE #LogEntries
DECLARE @Body VARCHAR(200), @Count VARCHAR(50), @endtime DATETIME;
SET @endtime = GETDATE();
DECLARE @starttime DATETIME;
SET @starttime = DATEADD(hh, -1, @endtime);
IF OBJECT_ID('tempdb..#LogEntries') IS NOT NULL
DROP TABLE #LogEntries;
CREATE TABLE #LogEntries
@tejaswidatla
tejaswidatla / usp_cpuAlert_all_servers.sql
Created January 9, 2018 09:34
CPU Utilization of servers
USE [Admin]
GO
CREATE PROCEDURE [dbo].[usp_cpuAlert_all_servers]
AS
SET NOCOUNT ON
DECLARE @SQL NVARCHAR(2000);
@tejaswidatla
tejaswidatla / USP_PING_ALERT.sql
Created January 9, 2018 09:30
Ping alert when the sql instance of server is not accessible
USE [Admin]
GO
-------------------------------------------------------------------------------------------------------------------------
/*
Procedure Name : USP_PING_ALERT
Descriptions : Procedure determines the current state of SQL Services
*/
@tejaswidatla
tejaswidatla / backup_report.sql
Created January 9, 2018 09:29
Back up failure reports
USE [Admin]
GO
CREATE procedure [dbo].[backup_report]
as
begin
declare @serv nvarchar(35)
declare @string varchar (500)
truncate table bkp_report
USE [Admin]
GO
/*
Name: USP_Fragmentation_Report
Description: This SP uses linked servers to connect to all the servers whose names are present in table
SmartReIndex_servers and pulls the latest reindex details and populates that data into table fragementation_Report
PreRequisite: 1. Smart ReIndex has to be configured in a server in order for this SP to work 2.Server name
should be added to the table SmartReIndex_servers and linked server should be created for that server
*/
@tejaswidatla
tejaswidatla / Create_snapshot.sql
Created December 29, 2017 10:32
Drop and create snapshot to access mirror database
USE [master]
/*
Procedure Name : USP_Create_Snapshot
Description : Creates snapshot for the database whose name is passed a parameter to this SP
Execution Instruction : EXEC dbo.USP_Create_Snapshot @DBName
Input Parameters : @DBName- database name
*/
CREATE Proc [dbo].[USP_Create_Snapshot](@DBName sysname)
AS