Skip to content

Commit eb37278

Browse files
committed
Adding more projects
Adding more projects
1 parent cb4ee50 commit eb37278

21 files changed

+390
-271
lines changed
11.5 KB
Binary file not shown.

Backup-Restore/2) Script Out DB Permissions in case of DB Refresh.sql

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
DECLARE @_specificLoginName VARCHAR(250);
2+
SET @_specificLoginName = '';
3+
14
DECLARE
25
@sql VARCHAR(2048)
36
,@sort INT

BlitzQueries/BlitzQueries.ssmssqlproj

+8-44
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
<Items>
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
55
<Items>
6-
<ConnectionNode Name="BAN-2ADWIVEDI-L:CORPORATE\adwivedi">
7-
<Created>2018-07-02T09:16:00.3182224+05:30</Created>
8-
<Type>SQL</Type>
9-
<Server>BAN-2ADWIVEDI-L</Server>
10-
<UserName />
11-
<Authentication>Windows Authentication</Authentication>
12-
<InitialDB />
13-
<LoginTimeout>30</LoginTimeout>
14-
<ExecutionTimeout>0</ExecutionTimeout>
15-
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16-
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17-
</ConnectionNode>
186
<ConnectionNode Name="BAN-2ADWIVEDI-L:sa">
197
<Created>2018-06-13T16:03:02.7281313+05:30</Created>
208
<Type>SQL</Type>
@@ -27,37 +15,13 @@
2715
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
2816
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
2917
</ConnectionNode>
30-
<ConnectionNode Name="TUL1CIPCNPDB1:CORPORATE\adwivedi">
31-
<Created>2018-06-25T11:10:27.1229725+05:30</Created>
32-
<Type>SQL</Type>
33-
<Server>TUL1CIPCNPDB1</Server>
34-
<UserName />
35-
<Authentication>Windows Authentication</Authentication>
36-
<InitialDB />
37-
<LoginTimeout>30</LoginTimeout>
38-
<ExecutionTimeout>0</ExecutionTimeout>
39-
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
40-
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
41-
</ConnectionNode>
42-
<ConnectionNode Name="TUL1CIPEDB2:CORPORATE\adwivedi">
43-
<Created>2018-06-18T22:17:38.8911865+05:30</Created>
44-
<Type>SQL</Type>
45-
<Server>TUL1CIPEDB2</Server>
46-
<UserName />
47-
<Authentication>Windows Authentication</Authentication>
48-
<InitialDB />
49-
<LoginTimeout>30</LoginTimeout>
50-
<ExecutionTimeout>0</ExecutionTimeout>
51-
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
52-
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
53-
</ConnectionNode>
5418
</Items>
5519
</LogicalFolder>
5620
<LogicalFolder Name="Queries" Type="0" Sorted="true">
5721
<Items>
5822
<FileNode Name="Blitz.sql">
59-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
60-
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
23+
<AssociatedConnectionMoniker />
24+
<AssociatedConnSrvName />
6125
<AssociatedConnUserName />
6226
<FullPath>Blitz.sql</FullPath>
6327
</FileNode>
@@ -68,8 +32,8 @@
6832
<FullPath>BlitzCache.sql</FullPath>
6933
</FileNode>
7034
<FileNode Name="blitzFirst.sql">
71-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
72-
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
35+
<AssociatedConnectionMoniker />
36+
<AssociatedConnSrvName />
7337
<AssociatedConnUserName />
7438
<FullPath>blitzFirst.sql</FullPath>
7539
</FileNode>
@@ -98,8 +62,8 @@
9862
<FullPath>CREATE TABLE [dbo].[whatIsRunning].sql</FullPath>
9963
</FileNode>
10064
<FileNode Name="Other queries.sql">
101-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
102-
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
65+
<AssociatedConnectionMoniker />
66+
<AssociatedConnSrvName />
10367
<AssociatedConnUserName />
10468
<FullPath>Other queries.sql</FullPath>
10569
</FileNode>
@@ -128,8 +92,8 @@
12892
<FullPath>who_is_active_v11_30(Modified).sql</FullPath>
12993
</FileNode>
13094
<FileNode Name="whoIsActive.sql">
131-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
132-
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
95+
<AssociatedConnectionMoniker />
96+
<AssociatedConnSrvName />
13397
<AssociatedConnUserName />
13498
<FullPath>whoIsActive.sql</FullPath>
13599
</FileNode>

BlitzQueries/whoIsActive.sql

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ EXEC sp_WhoIsActive @get_full_inner_text=1, @get_transaction_info=1, @get_task_i
77
-- EXEC sp_WhoIsActive @help = 1;
88

99
EXEC sp_healthcheck @p_getExecutionPlan = 1;
10+
-- EXEC [dbo].[sp_HealthCheck] '?'
11+
1012
/*
1113
$instance = 'ANN1VESPDB01';
1214
$excelPath = "C:\Temp\$instance.xlsx";

Blocking Alert/0. Overview.sql

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- https://social.msdn.microsoft.com/Forums/sqlserver/en-US/945cab5d-b8eb-4c15-93ff-b4ddbba1f7f2/creating-an-alert-for-blocked-process-threshold?forum=sqldatabaseengine
2+
/*
3+
1) Create a table BLOCKED_PROCESS_REPORT in MSDB daabase.
4+
2) Create a WMI based ALERT to capture BLOCKED PROCESS based on THREASHOLD value (in this example its set to 20 seconds).
5+
3) Create a SQL AGENT JOB which will execute once this ALERT got fired. This job will write information to a table and then send an email alert.
6+
4) It will send an email which will provide BLOCKING GRAPH like below which you can monitor later on.
7+
*/
8+
exec sp_configure 'show advanced options', 1 ;
9+
GO
10+
RECONFIGURE ;
11+
GO
12+
exec sp_configure 'blocked process threshold', 300 ; -- 1 minutes
13+
GO
14+
RECONFIGURE ;
15+
GO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exec sp_configure 'show advanced options', 1 ;
2+
GO
3+
RECONFIGURE ;
4+
GO
5+
exec sp_configure 'blocked process threshold', 20 ; -- 1 minutes
6+
GO
7+
RECONFIGURE ;
8+
GO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
USE [DBA]
2+
GO
3+
4+
CREATE TABLE [dbo].[WhoIsActive_ResultSets]
5+
(
6+
[dd hh:mm:ss.mss] [varchar](8000) NULL,
7+
[dd hh:mm:ss.mss (avg)] [varchar](15) NULL,
8+
[session_id] [smallint] NOT NULL,
9+
[sql_text] [xml] NULL,
10+
[sql_command] [xml] NULL,
11+
[login_name] [nvarchar](128) NOT NULL,
12+
[wait_info] [nvarchar](4000) NULL,
13+
[tasks] [varchar](30) NULL,
14+
[tran_log_writes] [nvarchar](4000) NULL,
15+
[CPU] [varchar](30) NULL,
16+
[tempdb_allocations] [varchar](30) NULL,
17+
[tempdb_current] [varchar](30) NULL,
18+
[blocking_session_id] [smallint] NULL,
19+
[blocked_session_count] [varchar](30) NULL,
20+
[reads] [varchar](30) NULL,
21+
[writes] [varchar](30) NULL,
22+
[context_switches] [varchar](30) NULL,
23+
[physical_io] [varchar](30) NULL,
24+
[physical_reads] [varchar](30) NULL,
25+
[locks] [xml] NULL,
26+
[used_memory] [varchar](30) NULL,
27+
[status] [varchar](30) NOT NULL,
28+
[tran_start_time] [datetime] NULL,
29+
[open_tran_count] [varchar](30) NULL,
30+
[percent_complete] [varchar](30) NULL,
31+
[host_name] [nvarchar](128) NULL,
32+
[database_name] [nvarchar](128) NULL,
33+
[program_name] [nvarchar](128) NULL,
34+
[additional_info] [xml] NULL,
35+
[start_time] [datetime] NOT NULL,
36+
[login_time] [datetime] NULL,
37+
[request_id] [int] NULL,
38+
[collection_time] [datetime] NOT NULL
39+
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
40+
GO
41+
42+
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
USE [msdb]
2+
GO
3+
4+
/****** Object: Job [DBA - Log_With_sp_WhoIsActive] Script Date: 8/3/2018 6:14:03 AM ******/
5+
BEGIN TRANSACTION
6+
DECLARE @ReturnCode INT
7+
SELECT @ReturnCode = 0
8+
/****** Object: JobCategory [Database Maintenance] Script Date: 8/3/2018 6:14:03 AM ******/
9+
IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'Database Maintenance' AND category_class=1)
10+
BEGIN
11+
EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'Database Maintenance'
12+
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
13+
14+
END
15+
16+
DECLARE @jobId BINARY(16)
17+
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'DBA - Log_With_sp_WhoIsActive',
18+
@enabled=1,
19+
@notify_level_eventlog=0,
20+
@notify_level_email=0,
21+
@notify_level_netsend=0,
22+
@notify_level_page=0,
23+
@delete_level=0,
24+
@description=N'This job will log activities using Adam Mechanic''s [sp_whoIsActive] stored procedure.
25+
26+
Results are saved into master..WhoIsActive_ResultSets table.
27+
28+
Job will run every 30 seconds once started.',
29+
@category_name=N'Database Maintenance',
30+
@owner_login_name=N'sa', @job_id = @jobId OUTPUT
31+
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
32+
/****** Object: Step [Log activities with [sp_WhoIsActive]] Script Date: 8/3/2018 6:14:03 AM ******/
33+
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Log activities with [sp_WhoIsActive]',
34+
@step_id=1,
35+
@cmdexec_success_code=0,
36+
@on_success_action=1,
37+
@on_success_step_id=0,
38+
@on_fail_action=2,
39+
@on_fail_step_id=0,
40+
@retry_attempts=0,
41+
@retry_interval=0,
42+
@os_run_priority=0, @subsystem=N'TSQL',
43+
@command=N'DECLARE @destination_table VARCHAR(4000);
44+
SET @destination_table = ''DBA.dbo.WhoIsActive_ResultSets'';
45+
46+
EXEC master..sp_WhoIsActive @get_full_inner_text=1, @get_transaction_info=1, @get_task_info=2, @get_locks=1, @get_avg_time=1, @get_additional_info=1, @find_block_leaders=1, @get_outer_command =1,
47+
@destination_table = @destination_table ;',
48+
@database_name=N'DBA',
49+
@flags=0
50+
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
51+
EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1
52+
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
53+
EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'
54+
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
55+
COMMIT TRANSACTION
56+
GOTO EndSave
57+
QuitWithRollback:
58+
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
59+
EndSave:
60+
GO
61+
62+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
USE [msdb]
2+
GO
3+
4+
DECLARE @p_job_id BINARY(16);
5+
select @p_job_id = job_id from msdb..sysjobs_view as j where j.name = 'DBA - Log_With_sp_WhoIsActive';
6+
7+
/****** Object: Alert [Blocked Process Threshold > 5 Minutes] Script Date: 8/3/2018 4:33:14 PM ******/
8+
EXEC msdb.dbo.sp_add_alert @name=N'Blocked Process Threshold > 5 Minutes',
9+
@message_id=0,
10+
@severity=0,
11+
@enabled=1,
12+
@delay_between_responses=0,
13+
@include_event_description_in=1,
14+
@notification_message=N'Kindly check session details involved in blocking by using below query.
15+
16+
SELECT DENSE_RANK()OVER(ORDER BY collection_time ASC) AS CollectionBatchNO, *
17+
FROM [DBA].[dbo].[WhoIsActive_ResultSets] as r
18+
WHERE r.blocking_session_id IS NOT NULL OR r.blocked_session_count > 0;
19+
20+
Thanks & Regards,
21+
SQL Alerts',
22+
@category_name=N'[Uncategorized]',
23+
@wmi_namespace=N'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER',
24+
@wmi_query=N'SELECT * FROM BLOCKED_PROCESS_REPORT Where Duration >= 300000',
25+
@job_id = @p_job_id
26+
GO
27+
28+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
USE DBA;
2+
3+
SELECT DENSE_RANK()OVER(ORDER BY collection_time ASC) AS CollectionBatchNO, *
4+
FROM [DBA].[dbo].[WhoIsActive_ResultSets] as r
5+
WHERE r.blocking_session_id IS NOT NULL OR r.blocked_session_count > 0;
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0"?>
2+
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="Blocking Alert">
3+
<Items>
4+
<LogicalFolder Name="Connections" Type="2" Sorted="true">
5+
<Items />
6+
</LogicalFolder>
7+
<LogicalFolder Name="Queries" Type="0" Sorted="true">
8+
<Items>
9+
<FileNode Name="0. Overview.sql">
10+
<AssociatedConnectionMoniker />
11+
<AssociatedConnSrvName />
12+
<AssociatedConnUserName />
13+
<FullPath>0. Overview.sql</FullPath>
14+
</FileNode>
15+
<FileNode Name="1. Set 'Blocked Process Threshold' to 20 Seconds.sql">
16+
<AssociatedConnectionMoniker />
17+
<AssociatedConnSrvName />
18+
<AssociatedConnUserName />
19+
<FullPath>1. Set 'Blocked Process Threshold' to 20 Seconds.sql</FullPath>
20+
</FileNode>
21+
<FileNode Name="2. Create table [dbo].[WhoIsActive_ResultSets].sql">
22+
<AssociatedConnectionMoniker />
23+
<AssociatedConnSrvName />
24+
<AssociatedConnUserName />
25+
<FullPath>2. Create table [dbo].[WhoIsActive_ResultSets].sql</FullPath>
26+
</FileNode>
27+
<FileNode Name="3. Create Job [DBA - Log_With_sp_WhoIsActive].sql">
28+
<AssociatedConnectionMoniker />
29+
<AssociatedConnSrvName />
30+
<AssociatedConnUserName />
31+
<FullPath>3. Create Job [DBA - Log_With_sp_WhoIsActive].sql</FullPath>
32+
</FileNode>
33+
<FileNode Name="4. Create Alert [Blocked Process Threshold greator than 5 Minutes].sql">
34+
<AssociatedConnectionMoniker />
35+
<AssociatedConnSrvName />
36+
<AssociatedConnUserName />
37+
<FullPath>4. Create Alert [Blocked Process Threshold greator than 5 Minutes].sql</FullPath>
38+
</FileNode>
39+
<FileNode Name="5. Fetch Blocking Information.sql">
40+
<AssociatedConnectionMoniker />
41+
<AssociatedConnSrvName />
42+
<AssociatedConnUserName />
43+
<FullPath>5. Fetch Blocking Information.sql</FullPath>
44+
</FileNode>
45+
</Items>
46+
</LogicalFolder>
47+
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
48+
<Items />
49+
</LogicalFolder>
50+
</Items>
51+
</SqlWorkbenchSqlProject>

Extended Events/Extended Events.ssmssqlproj

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,13 @@
22
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="Extended Events">
33
<Items>
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
5-
<Items>
6-
<ConnectionNode Name="TUL1CIPEDB2:CORPORATE\adwivedi">
7-
<Created>2018-06-18T14:08:18.3855874+05:30</Created>
8-
<Type>SQL</Type>
9-
<Server>TUL1CIPEDB2</Server>
10-
<UserName />
11-
<Authentication>Windows Authentication</Authentication>
12-
<InitialDB>master</InitialDB>
13-
<LoginTimeout>30</LoginTimeout>
14-
<ExecutionTimeout>0</ExecutionTimeout>
15-
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16-
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17-
</ConnectionNode>
18-
</Items>
5+
<Items />
196
</LogicalFolder>
207
<LogicalFolder Name="Queries" Type="0" Sorted="true">
218
<Items>
229
<FileNode Name="01) XEvent Definition.sql">
23-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:TUL1CIPEDB2:True</AssociatedConnectionMoniker>
24-
<AssociatedConnSrvName>TUL1CIPEDB2</AssociatedConnSrvName>
10+
<AssociatedConnectionMoniker />
11+
<AssociatedConnSrvName />
2512
<AssociatedConnUserName />
2613
<FullPath>01) XEvent Definition.sql</FullPath>
2714
</FileNode>

Hekathon/Hekathon.ssmssqlproj

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
<Items>
44
<LogicalFolder Name="Connections" Type="2" Sorted="true">
55
<Items>
6-
<ConnectionNode Name="BAN-2ADWIVEDI-L:CORPORATE\adwivedi">
7-
<Created>2018-05-10T15:49:41.2421658+05:30</Created>
8-
<Type>SQL</Type>
9-
<Server>BAN-2ADWIVEDI-L</Server>
10-
<UserName />
11-
<Authentication>Windows Authentication</Authentication>
12-
<InitialDB />
13-
<LoginTimeout>30</LoginTimeout>
14-
<ExecutionTimeout>0</ExecutionTimeout>
15-
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
16-
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
17-
</ConnectionNode>
186
<ConnectionNode Name="BAN-2ADWIVEDI-L:sa">
197
<Created>2018-05-08T20:10:36.8025451+05:30</Created>
208
<Type>SQL</Type>
@@ -32,8 +20,8 @@
3220
<LogicalFolder Name="Queries" Type="0" Sorted="true">
3321
<Items>
3422
<FileNode Name="01. Create Database.sql">
35-
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:BAN-2ADWIVEDI-L:True</AssociatedConnectionMoniker>
36-
<AssociatedConnSrvName>BAN-2ADWIVEDI-L</AssociatedConnSrvName>
23+
<AssociatedConnectionMoniker />
24+
<AssociatedConnSrvName />
3725
<AssociatedConnUserName />
3826
<FullPath>01. Create Database.sql</FullPath>
3927
</FileNode>

0 commit comments

Comments
 (0)