@@ -185,8 +185,11 @@ You need to use an Azure storage account, and the path has to look like this: ht
185185 finding NVARCHAR (4000 )
186186 );
187187 DECLARE @d VARCHAR (40 ), @StringToExecute NVARCHAR (4000 ),@StringToExecuteParams NVARCHAR (500 ),@r NVARCHAR (200 ),@OutputTableFindings NVARCHAR (100 );
188+ DECLARE @ServerName NVARCHAR (256 )
188189 DECLARE @OutputDatabaseCheck BIT ;
189190 SET @d = CONVERT (VARCHAR (40 ), GETDATE (), 109 );
191+ SET @OutputTableFindings = ' [BlitzLockFindings]'
192+ SET @ServerName = (select @@ServerName )
190193 if (@OutputDatabaseName is not null )
191194 BEGIN -- if databaseName is set do some sanity checks and put [] around def.
192195 if ( (select name from sys .databases where name = @OutputDatabaseName) is null ) -- if database is invalid raiserror and set bitcheck
@@ -208,6 +211,7 @@ You need to use an Azure storage account, and the path has to look like this: ht
208211 if (@r is null ) -- if it is null there is no table, create it from above execution
209212 BEGIN
210213 select @StringToExecute = N ' use ' + @OutputDatabaseName + ' ;create table ' + @OutputSchemaName + ' .' + @OutputTableName + ' (
214+ ServerName NVARCHAR(256),
211215 deadlock_type NVARCHAR(256),
212216 event_date datetime,
213217 Database_Name NVARCHAR(256),
@@ -252,18 +256,34 @@ You need to use an Azure storage account, and the path has to look like this: ht
252256 BEGIN
253257 select @OutputTableFindings= N ' [BlitzLockFindings]' ,
254258 @StringToExecute = N ' use ' + @OutputDatabaseName + ' ;create table ' + @OutputSchemaName + ' .' + @OutputTableFindings + ' (
259+ ServerName NVARCHAR(256),
255260 check_id INT,
256261 database_name NVARCHAR(256),
257262 object_name NVARCHAR(1000),
258263 finding_group NVARCHAR(100),
259264 finding NVARCHAR(4000))' ,
260265 @StringToExecuteParams = N ' @OutputDatabaseName NVARCHAR(200),@OutputSchemaName NVARCHAR(100),@OutputTableFindings NVARCHAR(200)'
261-
262- RAISERROR (' create table statement %s' , 0 , 1 , @StringToExecute) WITH NOWAIT ;
263266 exec sp_executesql @StringToExecute, @StringToExecuteParams, @OutputDatabaseName,@OutputSchemaName,@OutputTableFindings
267+
264268 END
265269
266270 END
271+ -- create synonym for deadlockfindings.
272+ if ((select name from sys .objects where name = ' DeadlockFindings' and type_desc = ' SYNONYM' )IS NOT NULL )
273+ BEGIN
274+ RAISERROR (' found synonym' , 0 , 1 ) WITH NOWAIT ;
275+ drop synonym DeadlockFindings;
276+ END
277+ set @StringToExecute = ' CREATE SYNONYM DeadlockFindings FOR ' + @OutputDatabaseName + ' .' + @OutputSchemaName + ' .' + @OutputTableFindings;
278+ exec sp_executesql @StringToExecute
279+
280+ -- create synonym for deadlock table.
281+ if ((select name from sys .objects where name = ' DeadLockTbl' and type_desc = ' SYNONYM' ) IS NOT NULL )
282+ BEGIN
283+ drop SYNONYM DeadLockTbl;
284+ END
285+ set @StringToExecute = ' CREATE SYNONYM DeadLockTbl FOR ' + @OutputDatabaseName + ' .' + @OutputSchemaName + ' .' + @OutputTableName;
286+ exec sp_executesql @StringToExecute
267287
268288 END
269289 END
@@ -1125,8 +1145,7 @@ You need to use an Azure storage account, and the path has to look like this: ht
11251145 -- CREATE CLUSTERED INDEX cx_whatever ON #deadlock_owner_waiter (event_date, owner_id, waiter_id);
11261146 IF (@OutputDatabaseCheck = 0 )
11271147 BEGIN
1128- set @StringToExecute = ' CREATE SYNONYM DeadLockTbl FOR ' + @OutputDatabaseName + ' .' + @OutputSchemaName + ' .' + @OutputTableName;
1129- exec sp_executesql @StringToExecute
1148+
11301149 SET @d = CONVERT (VARCHAR (40 ), GETDATE (), 109 );
11311150 RAISERROR (' Results 1 %s' , 0 , 1 , @d) WITH NOWAIT ;
11321151 WITH deadlocks
@@ -1232,6 +1251,7 @@ You need to use an Azure storage account, and the path has to look like this: ht
12321251 WHERE dp .victim_id IS NULL
12331252 AND dp .login_name IS NOT NULL )
12341253 insert into DeadLockTbl (
1254+ ServerName,
12351255 deadlock_type,
12361256 event_date,
12371257 database_name ,
@@ -1266,7 +1286,8 @@ You need to use an Azure storage account, and the path has to look like this: ht
12661286 waiter_waiting_to_close,
12671287 deadlock_graph
12681288 )
1269- SELECT d .deadlock_type ,
1289+ SELECT @ServerName,
1290+ d .deadlock_type ,
12701291 d .event_date ,
12711292 DB_NAME (d .database_id ) AS database_name ,
12721293 ' Deadlock #'
@@ -1320,16 +1341,14 @@ You need to use an Azure storage account, and the path has to look like this: ht
13201341
13211342 drop SYNONYM DeadLockTbl; -- done insert into blitzlock table going to insert into findings table first create synonym.
13221343
1323-
1324- set @StringToExecute = ' CREATE SYNONYM DeadlockFindings FOR ' + @OutputDatabaseName + ' .' + @OutputSchemaName + ' .' + @OutputTableFindings ;
1325- exec sp_executesql @StringToExecute, N ' @OutputDatabaseName NVARCHAR(200),@OutputSchemaName NVARCHAR(100), @OutputTableFindings NVARCHAR(200)' ,
1326- @OutputDatabaseName,@OutputSchemaName,@OutputTableFindings
1344+ -- RAISERROR('att deadlock findings', 0, 1) WITH NOWAIT;
1345+
13271346
13281347 SET @d = CONVERT (VARCHAR (40 ), GETDATE (), 109 );
13291348 RAISERROR (' Findings %s' , 0 , 1 , @d) WITH NOWAIT ;
13301349
1331- Insert into DeadlockFindings
1332- SELECT df .check_id , df .database_name , df .object_name , df .finding_group , df .finding
1350+ Insert into DeadlockFindings (ServerName,check_id, database_name , object_name ,finding_group,finding)
1351+ SELECT @ServerName, df .check_id , df .database_name , df .object_name , df .finding_group , df .finding
13331352 FROM #deadlock_findings AS df
13341353 ORDER BY df .check_id
13351354 OPTION ( RECOMPILE );
0 commit comments