sync
This commit is contained in:
@@ -1,152 +1,152 @@
|
||||
SELECT TOP 100
|
||||
'longest query' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
--/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
--/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
/* longest queries */ [qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
--,[qs].[total_worker_time] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_physical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
/* average duration */ [qs].[total_elapsed_time] / [qs].[execution_count] DESC;
|
||||
|
||||
|
||||
SELECT TOP 100
|
||||
'most cpu' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
--/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
--/* longest queries */[qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
/* cpu intensive */ [qs].[total_worker_time] / [qs].[execution_count] DESC;
|
||||
--,[qs].[total_physical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
--/* average duration */,[qs].[total_elapsed_time] / [qs].[execution_count] DESC
|
||||
|
||||
|
||||
SELECT TOP 100
|
||||
'most physical reads' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
--/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
--/* longest queries */[qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
--,[qs].[total_worker_time] / [qs].[execution_count] DESC
|
||||
/* most disk activity */ [qs].[total_physical_reads] / [qs].[execution_count] DESC;
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
--/* average duration */,[qs].[total_elapsed_time] / [qs].[execution_count] DESC
|
||||
|
||||
SELECT TOP 100
|
||||
'longest query' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
--/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
--/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
/* longest queries */ [qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
--,[qs].[total_worker_time] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_physical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
/* average duration */ [qs].[total_elapsed_time] / [qs].[execution_count] DESC;
|
||||
|
||||
|
||||
SELECT TOP 100
|
||||
'most cpu' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
--/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
--/* longest queries */[qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
/* cpu intensive */ [qs].[total_worker_time] / [qs].[execution_count] DESC;
|
||||
--,[qs].[total_physical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
--/* average duration */,[qs].[total_elapsed_time] / [qs].[execution_count] DESC
|
||||
|
||||
|
||||
SELECT TOP 100
|
||||
'most physical reads' AS msg,
|
||||
GETDATE() AS [Collection Date],
|
||||
[qs].[execution_count] AS [Execution Count],
|
||||
SUBSTRING(
|
||||
[qt].[text],
|
||||
[qs].[statement_start_offset] / 2 + 1,
|
||||
(CASE
|
||||
WHEN [qs].[statement_end_offset] = -1 THEN
|
||||
LEN(CONVERT(NVARCHAR(MAX), [qt].[text])) * 2
|
||||
ELSE
|
||||
[qs].[statement_end_offset]
|
||||
END - [qs].[statement_start_offset]
|
||||
) / 2
|
||||
) AS [Query Text],
|
||||
DB_NAME([qt].[dbid]) AS [DB Name],
|
||||
[qs].[total_worker_time] AS [Total CPU Time],
|
||||
[qs].[total_worker_time] / [qs].[execution_count] AS [Avg CPU Time (ms)],
|
||||
[qs].[total_physical_reads] AS [Total Physical Reads],
|
||||
[qs].[total_physical_reads] / [qs].[execution_count] AS [Avg Physical Reads],
|
||||
[qs].[total_logical_reads] AS [Total Logical Reads],
|
||||
[qs].[total_logical_reads] / [qs].[execution_count] AS [Avg Logical Reads],
|
||||
[qs].[total_logical_writes] AS [Total Logical Writes],
|
||||
[qs].[total_logical_writes] / [qs].[execution_count] AS [Avg Logical Writes],
|
||||
[qs].[total_elapsed_time] AS [Total Duration],
|
||||
[qs].[total_elapsed_time] / 1000000.0 AS [Total Duration seconds],
|
||||
[qs].[total_elapsed_time] / [qs].[execution_count] / 1000000.0 AS [Avg Duration seconds],
|
||||
[qp].[query_plan] AS [Plan],
|
||||
[qs].[creation_time],
|
||||
[qs].[last_execution_time]
|
||||
FROM [sys].[dm_exec_query_stats] AS [qs]
|
||||
CROSS APPLY [sys].dm_exec_sql_text([qs].[sql_handle]) AS [qt]
|
||||
CROSS APPLY [sys].dm_exec_query_plan([qs].[plan_handle]) AS [qp]
|
||||
WHERE
|
||||
--/* most often used */ [qs].[execution_count] > 50
|
||||
--/* most CPU intensive */ [qs].[total_worker_time] / [qs].[execution_count] > 100 --[Avg CPU Time (ms)]
|
||||
/* most read IO */ [qs].[total_physical_reads] / [qs].[execution_count] > 1000 --[Avg Physical Reads]
|
||||
--/* most intesive in reads */ [qs].[total_logical_reads] / [qs].[execution_count] > 1000 --[Avg Logical Reads]
|
||||
--/* most IO intensive in write */ [qs].[total_logical_writes] / [qs].[execution_count] > 1000 --[Avg Logical Writes]
|
||||
--/* longest queries */[qs].[total_elapsed_time] / [qs].[execution_count] > 1000 --[Avg Duration (ms)]
|
||||
AND DB_NAME([qt].[dbid]) NOT IN ( 'master', 'msdb', 'model', 'tempDb' )
|
||||
ORDER BY
|
||||
--[Avg Logical Reads] DESC
|
||||
--[qs].[execution_count] DESC
|
||||
--,[qs].[total_worker_time] / [qs].[execution_count] DESC
|
||||
/* most disk activity */ [qs].[total_physical_reads] / [qs].[execution_count] DESC;
|
||||
--,[qs].[total_logical_reads] / [qs].[execution_count] DESC
|
||||
--,[qs].[total_logical_writes] / [qs].[execution_count] DESC;
|
||||
--/* average duration */,[qs].[total_elapsed_time] / [qs].[execution_count] DESC
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "2e06e4b5-85f0-4493-b17d-67a332f9e634",
|
||||
"prefix": "POS",
|
||||
"description": "list all POS",
|
||||
"body": "SELECT * \r\nFROM [Arizona].[dbo].[Point_of_sale] [pos]\r\nWHERE [pos].[POS_active]=1\r\nAND [pos].[POS_type] IN (1,2)\r\nAND [pos].[POS_number] < 99\r\n;\r\n"
|
||||
{
|
||||
"id": "2e06e4b5-85f0-4493-b17d-67a332f9e634",
|
||||
"prefix": "POS",
|
||||
"description": "list all POS",
|
||||
"body": "SELECT * \r\nFROM [Arizona].[dbo].[Point_of_sale] [pos]\r\nWHERE [pos].[POS_active]=1\r\nAND [pos].[POS_type] IN (1,2)\r\nAND [pos].[POS_number] < 99\r\n;\r\n"
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
# sql-snippets
|
||||
red-gate sql prompt snippets
|
||||
|
||||
Find in this repo my most often used and most useful red-gate sql prompt snippets
|
||||
# sql-snippets
|
||||
red-gate sql prompt snippets
|
||||
|
||||
Find in this repo my most often used and most useful red-gate sql prompt snippets
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "871e45ec-6fe6-4733-9783-259e7b8c8a06",
|
||||
"prefix": "amr_count",
|
||||
"description": "list a count per tables of amr waiting to be processed",
|
||||
"body": "\r\nDECLARE\r\n\t@OutParam VARCHAR(255),\r\n\t@DatabaseName VARCHAR(255),\r\n\t@OrganizationalUnitId INT,\r\n\t@PharmacyName VARCHAR(500),\r\n\t@ConnecticUser VARCHAR(255),\r\n\t@LatestReplicatedNonPriorizedMonitorRowId INT,\r\n\t@LatestReplicatedPriorizedMonitorRowId INT\r\n\r\n\tEXEC Arizona..sp_bmc_Bmc_Applic_Default @in_job_type = 3, @in_param_int_1 = NULL, @in_param_int_2 = NULL, @in_param_varchar_1 = 'cvCurrentOrganizationalUnit', @out_default_value = @OutParam OUTPUT, @out_param_int_1 = NULL\r\n\tSET @OrganizationalUnitId = CAST(@OutParam AS INT)\r\n\tSELECT @PharmacyName = AD_name + '-' + ou.ou_code FROM \tArizona..Address (READUNCOMMITTED) INNER JOIN Arizona..Organizational_unit (READUNCOMMITTED) ou on Address_ID = OU_address WHERE ou.Organizational_unit_ID = @OrganizationalUnitId\r\n\t\r\n\tSET @DatabaseName = 'Arizona'\t\r\n\t\t\r\n\tEXEC Arizona..sp_bmc_Bmc_Applic_Default @in_job_type = 3, @in_param_int_1 = NULL, @in_param_int_2 = NULL, @in_param_varchar_1 = 'cvConnecticAMRUser', @out_default_value = @OutParam OUTPUT, @out_param_int_1 = NULL\r\n\tSET @ConnecticUser = @OutParam \r\n\r\n\tSELECT @LatestReplicatedNonPriorizedMonitorRowId = amr.GetLatestReplicatedMonitorRowId(@DatabaseName,0)\r\n\tSELECT @LatestReplicatedPriorizedMonitorRowId = amr.GetLatestReplicatedMonitorRowId(@DatabaseName,1)\r\n\t\t\r\n SELECT [x].[Database],\r\n [x].[Table],\r\n [x].[Non treated MonitorRows of table]\r\n FROM (\r\n\t\tSELECT \r\n\t\t\t@DatabaseName 'Database',\r\n\t\t\tAMT_table_name 'Table',\r\n\t\t\tCOUNT(AMT_table_name) 'Non treated MonitorRows of table total',\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, COUNT(AMT_table_name)), 1),',',''''),'.00','') AS 'Non treated MonitorRows of table'\r\n\t\t\tFROM \r\n\t\t\t\tArizona..APS_monitor_row WITH (READUNCOMMITTED)\r\n\t\t\t\tINNER JOIN Arizona..APS_monitor_table (READUNCOMMITTED)\r\n\t\t\t\t\tON AMR_APS_monitor_table = APS_monitor_table_id\r\n\t\t\tWHERE\r\n\t\t\t\tAPS_monitor_row_id > @LatestReplicatedPriorizedMonitorRowId\r\n\t\t\t\tAND AMR_row_GUID IS NOT NULL\r\n\t\t\t\t-- Remove non transactional and not committed records.\r\n\t\t\t\tAND NOT (AMT_wait_for_commit = 1 AND AMR_user = @ConnecticUser AND AMR_type_of_change <> 6)\r\n\t\t\t\tAND AMR_user = @ConnecticUser\r\n\t\t\t\tAND AMT_used_by_connectic = 1\r\n\t\t\tGROUP BY \r\n\t\t\t\tAMT_table_name\r\n\r\n\t\tUNION ALL\r\n\r\n\t\tSELECT \r\n\t\t\t@DatabaseName 'Database',\r\n\t\t\tAMT_table_name 'Table',\r\n\t\t\tCOUNT(AMT_table_name) 'Non treated MonitorRows of table total',\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, COUNT(AMT_table_name)), 1),',',''''),'.00','') AS 'Non treated MonitorRows of table'\r\n\t\t\tFROM \r\n\t\t\t\tArizona..APS_monitor_row WITH (READUNCOMMITTED)\r\n\t\t\t\tINNER JOIN Arizona..APS_monitor_table (READUNCOMMITTED)\r\n\t\t\t\t\tON AMR_APS_monitor_table = APS_monitor_table_id\r\n\t\t\tWHERE\r\n\t\t\t\tAPS_monitor_row_id > @LatestReplicatedNonPriorizedMonitorRowId\r\n\t\t\t\tAND AMR_row_GUID IS NOT NULL\r\n\t\t\t\t-- Remove non transactional and not committed records.\r\n\t\t\t\tAND NOT (AMT_wait_for_commit = 1 AND AMR_user = @ConnecticUser AND AMR_type_of_change <> 6)\r\n\t\t\t\tAND ISNULL(AMR_user, '') <> @ConnecticUser\r\n\t\t\t\tAND AMT_used_by_connectic = 1\r\n\t\t\tGROUP BY \r\n\t\t\t\tAMT_table_name\r\n\t\t\t\t\r\n\t\t)x \r\n ORDER BY [x].[Non treated MonitorRows of table total] DESC \r\n"
|
||||
{
|
||||
"id": "871e45ec-6fe6-4733-9783-259e7b8c8a06",
|
||||
"prefix": "amr_count",
|
||||
"description": "list a count per tables of amr waiting to be processed",
|
||||
"body": "\r\nDECLARE\r\n\t@OutParam VARCHAR(255),\r\n\t@DatabaseName VARCHAR(255),\r\n\t@OrganizationalUnitId INT,\r\n\t@PharmacyName VARCHAR(500),\r\n\t@ConnecticUser VARCHAR(255),\r\n\t@LatestReplicatedNonPriorizedMonitorRowId INT,\r\n\t@LatestReplicatedPriorizedMonitorRowId INT\r\n\r\n\tEXEC Arizona..sp_bmc_Bmc_Applic_Default @in_job_type = 3, @in_param_int_1 = NULL, @in_param_int_2 = NULL, @in_param_varchar_1 = 'cvCurrentOrganizationalUnit', @out_default_value = @OutParam OUTPUT, @out_param_int_1 = NULL\r\n\tSET @OrganizationalUnitId = CAST(@OutParam AS INT)\r\n\tSELECT @PharmacyName = AD_name + '-' + ou.ou_code FROM \tArizona..Address (READUNCOMMITTED) INNER JOIN Arizona..Organizational_unit (READUNCOMMITTED) ou on Address_ID = OU_address WHERE ou.Organizational_unit_ID = @OrganizationalUnitId\r\n\t\r\n\tSET @DatabaseName = 'Arizona'\t\r\n\t\t\r\n\tEXEC Arizona..sp_bmc_Bmc_Applic_Default @in_job_type = 3, @in_param_int_1 = NULL, @in_param_int_2 = NULL, @in_param_varchar_1 = 'cvConnecticAMRUser', @out_default_value = @OutParam OUTPUT, @out_param_int_1 = NULL\r\n\tSET @ConnecticUser = @OutParam \r\n\r\n\tSELECT @LatestReplicatedNonPriorizedMonitorRowId = amr.GetLatestReplicatedMonitorRowId(@DatabaseName,0)\r\n\tSELECT @LatestReplicatedPriorizedMonitorRowId = amr.GetLatestReplicatedMonitorRowId(@DatabaseName,1)\r\n\t\t\r\n SELECT [x].[Database],\r\n [x].[Table],\r\n [x].[Non treated MonitorRows of table]\r\n FROM (\r\n\t\tSELECT \r\n\t\t\t@DatabaseName 'Database',\r\n\t\t\tAMT_table_name 'Table',\r\n\t\t\tCOUNT(AMT_table_name) 'Non treated MonitorRows of table total',\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, COUNT(AMT_table_name)), 1),',',''''),'.00','') AS 'Non treated MonitorRows of table'\r\n\t\t\tFROM \r\n\t\t\t\tArizona..APS_monitor_row WITH (READUNCOMMITTED)\r\n\t\t\t\tINNER JOIN Arizona..APS_monitor_table (READUNCOMMITTED)\r\n\t\t\t\t\tON AMR_APS_monitor_table = APS_monitor_table_id\r\n\t\t\tWHERE\r\n\t\t\t\tAPS_monitor_row_id > @LatestReplicatedPriorizedMonitorRowId\r\n\t\t\t\tAND AMR_row_GUID IS NOT NULL\r\n\t\t\t\t-- Remove non transactional and not committed records.\r\n\t\t\t\tAND NOT (AMT_wait_for_commit = 1 AND AMR_user = @ConnecticUser AND AMR_type_of_change <> 6)\r\n\t\t\t\tAND AMR_user = @ConnecticUser\r\n\t\t\t\tAND AMT_used_by_connectic = 1\r\n\t\t\tGROUP BY \r\n\t\t\t\tAMT_table_name\r\n\r\n\t\tUNION ALL\r\n\r\n\t\tSELECT \r\n\t\t\t@DatabaseName 'Database',\r\n\t\t\tAMT_table_name 'Table',\r\n\t\t\tCOUNT(AMT_table_name) 'Non treated MonitorRows of table total',\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, COUNT(AMT_table_name)), 1),',',''''),'.00','') AS 'Non treated MonitorRows of table'\r\n\t\t\tFROM \r\n\t\t\t\tArizona..APS_monitor_row WITH (READUNCOMMITTED)\r\n\t\t\t\tINNER JOIN Arizona..APS_monitor_table (READUNCOMMITTED)\r\n\t\t\t\t\tON AMR_APS_monitor_table = APS_monitor_table_id\r\n\t\t\tWHERE\r\n\t\t\t\tAPS_monitor_row_id > @LatestReplicatedNonPriorizedMonitorRowId\r\n\t\t\t\tAND AMR_row_GUID IS NOT NULL\r\n\t\t\t\t-- Remove non transactional and not committed records.\r\n\t\t\t\tAND NOT (AMT_wait_for_commit = 1 AND AMR_user = @ConnecticUser AND AMR_type_of_change <> 6)\r\n\t\t\t\tAND ISNULL(AMR_user, '') <> @ConnecticUser\r\n\t\t\t\tAND AMT_used_by_connectic = 1\r\n\t\t\tGROUP BY \r\n\t\t\t\tAMT_table_name\r\n\t\t\t\t\r\n\t\t)x \r\n ORDER BY [x].[Non treated MonitorRows of table total] DESC \r\n"
|
||||
}
|
||||
@@ -1,421 +1,421 @@
|
||||
# Starter pipeline
|
||||
|
||||
|
||||
# Start with a minimal pipeline that you can customize to build and deploy your code.
|
||||
# Add steps that build, run tests, deploy, and more:
|
||||
# https://aka.ms/yaml
|
||||
|
||||
trigger:
|
||||
- main
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- task: SqlDacpacDeploymentOnMachineGroup@0
|
||||
displayName: _D03091 - INDEX - Load items CDS and prescribers from PharmIndex to Arizona - Central
|
||||
inputs:
|
||||
TaskType: 'sqlInline'
|
||||
InlineSql: |
|
||||
/* step 1 - Check download from Pharmindex is finished */
|
||||
use pharmindexTP
|
||||
GO
|
||||
|
||||
|
||||
|
||||
|
||||
declare @today datetime;
|
||||
|
||||
select @today = convert(datetime, convert(varchar(20), getdate(),102))
|
||||
|
||||
if not exists ( select top 1 *
|
||||
from BatchImportHistory bih
|
||||
where bih.Success = 1
|
||||
and bih.EndImportDate > @today)
|
||||
begin /* Download not OK */
|
||||
|
||||
raiserror('Pharmindex download in process, job not executed', 16,1)
|
||||
|
||||
end;
|
||||
|
||||
GO
|
||||
|
||||
/* step 2 - INDEX - Transfert PharmIndexTP to Arizona items, Prescriber using Checksum */
|
||||
begin try
|
||||
|
||||
declare @out_param_int_1 int
|
||||
execute[dbo].[pdx_loading]
|
||||
@in_job_type = 20
|
||||
,@skip_mapping = 0
|
||||
,@in_subsidiary = 100
|
||||
,@in_table_name = null
|
||||
,@in_debug = 0
|
||||
,@out_param_int_1 = @out_param_int_1 output
|
||||
|
||||
end try
|
||||
begin catch
|
||||
declare
|
||||
@mail_message nvarchar(2000),
|
||||
@mail_subject nvarchar(255);
|
||||
set @mail_message = ' <html><body><p>Résumé des erreurs dans le tableau ci-dessous : </p>' +'
|
||||
<table border="1" width="400px" height="400px">
|
||||
<tr>
|
||||
<th>ErrorNumber</th>
|
||||
<th>ErrorSeverity</th>
|
||||
<th>ErrorState</th>
|
||||
<th>ErrorProcedure</th>
|
||||
<th>ErrorLine</th>
|
||||
<th>ErrorMessage</th>
|
||||
</tr>' + '<tr valign="center">
|
||||
<td>' + isnull(convert(varchar, ERROR_NUMBER()), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_SEVERITY()), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_STATE()), '') + '</td>
|
||||
<td>' + isnull(ERROR_PROCEDURE(), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_LINE()), '') + '</td>
|
||||
<td>' + isnull(ERROR_MESSAGE(), '') + '</td>
|
||||
</tr>'+ '
|
||||
</table>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
set @mail_subject = 'INDEX - Transfert PharmIndex to PHGD_xx for items using checksum (Instance ' + @@SERVERNAME + ') - Job _D01941 - INDEX';
|
||||
|
||||
/* envoi du mail */
|
||||
exec Arizona.dbo.aps_Send_Mail_with_template
|
||||
@in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement',
|
||||
@in_param_varchar_3 = @mail_message,
|
||||
@in_param_subject = @mail_subject,
|
||||
@in_job_type = 4;
|
||||
|
||||
end catch
|
||||
go
|
||||
|
||||
/* step 3 - INDEX - Control if exist prescribers with same contract number than an OU */
|
||||
use Arizona
|
||||
|
||||
declare @subject varchar(8000)
|
||||
, @errmsg varchar(8000)
|
||||
|
||||
select @errmsg = 'Les pharmacies suivantes ont un concordat identique à celui d''un prescripteur actif'
|
||||
|
||||
select @errmsg = @errmsg + char(13) + char(10) + ou1.OU_code + char(9) + ou1.OU_short_name + char(9) + pr1.PHPR_contract_number
|
||||
from PH_prescriber pr1 with (nolock)
|
||||
join PH_prescriber pr2 with (nolock)
|
||||
on pr2.PH_prescriber_GUID <> pr1.PH_prescriber_GUID
|
||||
and pr2.PHPR_contract_number = pr1.PHPR_contract_number
|
||||
and pr2.PHPR_status = pr1.PHPR_status
|
||||
join Organizational_unit ou1 with (nolock)
|
||||
on ou1.OU_address = pr1.PHPR_address
|
||||
left outer join Organizational_unit ou2 with (nolock)
|
||||
on ou2.OU_address = pr2.PHPR_address
|
||||
where pr1.PHPR_status = 1
|
||||
and ou2.Organizational_unit_ID is null
|
||||
and exists(select 1
|
||||
from OU_store_history oust with (nolock)
|
||||
where oust.OUSH_organizational_unit = ou1.Organizational_unit_ID
|
||||
and (oust.OUSH_end_date is null or oust.OUSH_end_date >= getdate()))
|
||||
order by ou1.OU_code
|
||||
|
||||
if @@ROWCOUNT > 0
|
||||
begin
|
||||
|
||||
select @subject = QUOTENAME(OBJECT_SCHEMA_NAME(@@PROCID))
|
||||
+'.'+QUOTENAME(OBJECT_NAME(@@PROCID))
|
||||
|
||||
exec aps_Send_Mail_with_template
|
||||
@in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement',
|
||||
@in_param_varchar_3 = @errmsg,
|
||||
@in_param_subject = @subject,
|
||||
@in_job_type = 4;
|
||||
|
||||
end
|
||||
|
||||
go
|
||||
|
||||
|
||||
/* step 4 - Update PEXF */
|
||||
declare @cvPHGDPriceCodePEXF int,
|
||||
@SubsidiaryId int,
|
||||
@w_date date
|
||||
|
||||
select @SubsidiaryId = 1000,
|
||||
@cvPHGDPriceCodePEXF = NULL,
|
||||
@w_date = getdate()
|
||||
|
||||
exec arizona.dbo.sp_bmc_Bmc_Applic_Default
|
||||
@in_job_type = 3,
|
||||
@in_param_int_1 = NULL,
|
||||
@in_param_int_2 = @SubsidiaryId,
|
||||
@in_param_varchar_1 = 'cvPHGDPriceCodePSL1',
|
||||
@out_default_value = @cvPHGDPriceCodePEXF output,
|
||||
@out_param_int_1 = null
|
||||
|
||||
|
||||
if @cvPHGDPriceCodePEXF is null
|
||||
begin
|
||||
select @SubsidiaryId = 100
|
||||
|
||||
exec arizona.dbo.sp_bmc_Bmc_Applic_Default
|
||||
@in_job_type = 3,
|
||||
@in_param_int_1 = NULL,
|
||||
@in_param_int_2 = @SubsidiaryId,
|
||||
@in_param_varchar_1 = 'cvPHGDPriceCodePSL1',
|
||||
@out_default_value = @cvPHGDPriceCodePEXF output,
|
||||
@out_param_int_1 = null
|
||||
end
|
||||
|
||||
/*-------------
|
||||
Fermeture des PEXF sans Adresse pour les articles avec insurance code not in (10, 11)
|
||||
------------------*/
|
||||
|
||||
Update top(5000) FP set fp.fp_end_date = DATEADD(d,-1,@w_date)
|
||||
from subsidiary SUB with (nolock)
|
||||
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code not in ('10', '11')
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
|
||||
/*---------------------------------------
|
||||
Clôture du PEXF sans adresse à la date -1 de la start_date du prix PEXF avec adresse
|
||||
pour les articles LS.
|
||||
|
||||
Nous recréons un PEXF avec la bonne start_date et le bon prix afin que la facturation aux caisse maladie soit OK
|
||||
--------------*/
|
||||
|
||||
Update top(5000) FP1 set fp1.fp_end_date = DATEADD(d,-1,fp.FP_start_date)
|
||||
from subsidiary SUB with (nolock)
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is not null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock)
|
||||
where FP2.FP_item = FP.FP_item
|
||||
and FP2.FP_price_code = fp.FP_price_code
|
||||
and FP2.fp_subsidiary = FP.fp_subsidiary
|
||||
and FP2.FP_address is not null
|
||||
and FP2.FP_start_date < GETDATE()
|
||||
and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE()
|
||||
|
||||
order by FP2.FP_start_date desc
|
||||
)
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code in ('10', '11')
|
||||
|
||||
join Fixed_price FP1 with (nolock)
|
||||
on FP1.FP_price_code = prc.price_code_id
|
||||
and FP1.fp_subsidiary = sub.subsidiary_id
|
||||
and FP1.FP_address is null
|
||||
and FP1.FP_start_date < GETDATE()
|
||||
and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP1.FP_item = FP.FP_item
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
and isnull(FP.FP_tax_free_price_per_unit,0) <> isnull(FP1.FP_tax_free_price_per_unit,0)
|
||||
|
||||
/*----------
|
||||
|
||||
Creation PEXF sans adresse avec start_date et prix du PEXF avec Adresse pour LS (Le plus récent)
|
||||
|
||||
------------*/
|
||||
|
||||
declare
|
||||
|
||||
@New_fixed_price_ID int,
|
||||
@nb_fixed_price int ,
|
||||
@fp_subsidiary int,
|
||||
@fp_tariff_type int,
|
||||
@fp_item int,
|
||||
@fp_currency int,
|
||||
@fp_price_code int,
|
||||
@fp_sales_tax_code int,
|
||||
@FP_start_date datetime,
|
||||
@FP_tax_free_price_per_unit dec(14,2)
|
||||
|
||||
|
||||
SELECT @nb_fixed_price = 1
|
||||
|
||||
/*-- Declaration du curseur c_external_item --*/
|
||||
declare c_FP cursor local forward_only read_only static for
|
||||
|
||||
select FP.fp_subsidiary,
|
||||
FP.fp_tariff_type,
|
||||
FP.fp_item,
|
||||
FP.fp_currency,
|
||||
FP.fp_price_code,
|
||||
FP.fp_sales_tax_code,
|
||||
FP.FP_start_date,
|
||||
FP.FP_tax_free_price_per_unit
|
||||
|
||||
from subsidiary SUB with (nolock)
|
||||
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is not null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock)
|
||||
where FP2.FP_item = FP.FP_item
|
||||
and FP2.FP_price_code = fp.FP_price_code
|
||||
and FP2.fp_subsidiary = FP.fp_subsidiary
|
||||
and FP2.FP_address is not null
|
||||
and FP2.FP_start_date < GETDATE()
|
||||
and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE()
|
||||
order by FP2.FP_start_date desc
|
||||
)
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code in ('10', '11')
|
||||
|
||||
left outer join Fixed_price FP1 with (nolock)
|
||||
on FP1.FP_price_code = prc.price_code_id
|
||||
and FP1.fp_subsidiary = sub.subsidiary_id
|
||||
and FP1.FP_address is null
|
||||
and FP1.FP_start_date < GETDATE()
|
||||
and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP1.FP_item = FP.FP_item
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
and FP1.Fixed_price_ID is null
|
||||
|
||||
order by 1
|
||||
|
||||
open c_FP;
|
||||
|
||||
fetch next from c_FP
|
||||
into @fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit
|
||||
|
||||
while (@@fetch_status <> -1 )
|
||||
begin
|
||||
|
||||
if (@@fetch_status <> -2 )
|
||||
begin
|
||||
|
||||
/*----- Recherche dernier ID pour Fixed_Price -----*/
|
||||
select @New_fixed_price_ID = null
|
||||
|
||||
exec sp_bmc_GetNextID
|
||||
@in_key = 'fixed_price',
|
||||
@in_id_column = 'fixed_price_id',
|
||||
@in_nbr_of_record = @nb_fixed_price,
|
||||
@out_id = @New_fixed_price_id output
|
||||
|
||||
insert fixed_price
|
||||
(fixed_price_id,
|
||||
|
||||
fp_subsidiary,
|
||||
fp_tariff_type,
|
||||
fp_item,
|
||||
fp_currency,
|
||||
fp_price_code,
|
||||
fp_sales_tax_code,
|
||||
fp_start_date,
|
||||
fp_tax_free_price_per_unit ,
|
||||
|
||||
fp_unit_code,
|
||||
FP_price_per_unit_unit_code,
|
||||
fp_final_discount_possible,
|
||||
FP_discount_level_1_possible,
|
||||
FP_discount_level_2_possible,
|
||||
FP_origin,
|
||||
FP_remark
|
||||
|
||||
)
|
||||
select
|
||||
@New_fixed_price_id,
|
||||
|
||||
@fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
'Automatic Insert PEXF '
|
||||
|
||||
/*----- fin du curseur -----*/
|
||||
|
||||
|
||||
end /* (@@fetch_status <> -2 ) */
|
||||
|
||||
fetch next from c_FP
|
||||
into @fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit
|
||||
|
||||
end /* (@@fetch_status <> -1 ) */
|
||||
|
||||
close c_FP;
|
||||
deallocate c_FP;
|
||||
|
||||
ServerName: 'localhost'
|
||||
DatabaseName: 'master'
|
||||
AuthScheme: 'windowsAuthentication'
|
||||
|
||||
- script: echo Hello, world!
|
||||
displayName: 'Run a one-line script'
|
||||
|
||||
- script: |
|
||||
echo Add other tasks to build, test, and deploy your project.
|
||||
echo See https://aka.ms/yaml
|
||||
displayName: 'Run a multi-line script'
|
||||
# Starter pipeline
|
||||
|
||||
|
||||
# Start with a minimal pipeline that you can customize to build and deploy your code.
|
||||
# Add steps that build, run tests, deploy, and more:
|
||||
# https://aka.ms/yaml
|
||||
|
||||
trigger:
|
||||
- main
|
||||
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- task: SqlDacpacDeploymentOnMachineGroup@0
|
||||
displayName: _D03091 - INDEX - Load items CDS and prescribers from PharmIndex to Arizona - Central
|
||||
inputs:
|
||||
TaskType: 'sqlInline'
|
||||
InlineSql: |
|
||||
/* step 1 - Check download from Pharmindex is finished */
|
||||
use pharmindexTP
|
||||
GO
|
||||
|
||||
|
||||
|
||||
|
||||
declare @today datetime;
|
||||
|
||||
select @today = convert(datetime, convert(varchar(20), getdate(),102))
|
||||
|
||||
if not exists ( select top 1 *
|
||||
from BatchImportHistory bih
|
||||
where bih.Success = 1
|
||||
and bih.EndImportDate > @today)
|
||||
begin /* Download not OK */
|
||||
|
||||
raiserror('Pharmindex download in process, job not executed', 16,1)
|
||||
|
||||
end;
|
||||
|
||||
GO
|
||||
|
||||
/* step 2 - INDEX - Transfert PharmIndexTP to Arizona items, Prescriber using Checksum */
|
||||
begin try
|
||||
|
||||
declare @out_param_int_1 int
|
||||
execute[dbo].[pdx_loading]
|
||||
@in_job_type = 20
|
||||
,@skip_mapping = 0
|
||||
,@in_subsidiary = 100
|
||||
,@in_table_name = null
|
||||
,@in_debug = 0
|
||||
,@out_param_int_1 = @out_param_int_1 output
|
||||
|
||||
end try
|
||||
begin catch
|
||||
declare
|
||||
@mail_message nvarchar(2000),
|
||||
@mail_subject nvarchar(255);
|
||||
set @mail_message = ' <html><body><p>Résumé des erreurs dans le tableau ci-dessous : </p>' +'
|
||||
<table border="1" width="400px" height="400px">
|
||||
<tr>
|
||||
<th>ErrorNumber</th>
|
||||
<th>ErrorSeverity</th>
|
||||
<th>ErrorState</th>
|
||||
<th>ErrorProcedure</th>
|
||||
<th>ErrorLine</th>
|
||||
<th>ErrorMessage</th>
|
||||
</tr>' + '<tr valign="center">
|
||||
<td>' + isnull(convert(varchar, ERROR_NUMBER()), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_SEVERITY()), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_STATE()), '') + '</td>
|
||||
<td>' + isnull(ERROR_PROCEDURE(), '') + '</td>
|
||||
<td>' + isnull(convert(varchar, ERROR_LINE()), '') + '</td>
|
||||
<td>' + isnull(ERROR_MESSAGE(), '') + '</td>
|
||||
</tr>'+ '
|
||||
</table>
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
set @mail_subject = 'INDEX - Transfert PharmIndex to PHGD_xx for items using checksum (Instance ' + @@SERVERNAME + ') - Job _D01941 - INDEX';
|
||||
|
||||
/* envoi du mail */
|
||||
exec Arizona.dbo.aps_Send_Mail_with_template
|
||||
@in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement',
|
||||
@in_param_varchar_3 = @mail_message,
|
||||
@in_param_subject = @mail_subject,
|
||||
@in_job_type = 4;
|
||||
|
||||
end catch
|
||||
go
|
||||
|
||||
/* step 3 - INDEX - Control if exist prescribers with same contract number than an OU */
|
||||
use Arizona
|
||||
|
||||
declare @subject varchar(8000)
|
||||
, @errmsg varchar(8000)
|
||||
|
||||
select @errmsg = 'Les pharmacies suivantes ont un concordat identique à celui d''un prescripteur actif'
|
||||
|
||||
select @errmsg = @errmsg + char(13) + char(10) + ou1.OU_code + char(9) + ou1.OU_short_name + char(9) + pr1.PHPR_contract_number
|
||||
from PH_prescriber pr1 with (nolock)
|
||||
join PH_prescriber pr2 with (nolock)
|
||||
on pr2.PH_prescriber_GUID <> pr1.PH_prescriber_GUID
|
||||
and pr2.PHPR_contract_number = pr1.PHPR_contract_number
|
||||
and pr2.PHPR_status = pr1.PHPR_status
|
||||
join Organizational_unit ou1 with (nolock)
|
||||
on ou1.OU_address = pr1.PHPR_address
|
||||
left outer join Organizational_unit ou2 with (nolock)
|
||||
on ou2.OU_address = pr2.PHPR_address
|
||||
where pr1.PHPR_status = 1
|
||||
and ou2.Organizational_unit_ID is null
|
||||
and exists(select 1
|
||||
from OU_store_history oust with (nolock)
|
||||
where oust.OUSH_organizational_unit = ou1.Organizational_unit_ID
|
||||
and (oust.OUSH_end_date is null or oust.OUSH_end_date >= getdate()))
|
||||
order by ou1.OU_code
|
||||
|
||||
if @@ROWCOUNT > 0
|
||||
begin
|
||||
|
||||
select @subject = QUOTENAME(OBJECT_SCHEMA_NAME(@@PROCID))
|
||||
+'.'+QUOTENAME(OBJECT_NAME(@@PROCID))
|
||||
|
||||
exec aps_Send_Mail_with_template
|
||||
@in_param_varchar_2 = 'HCI_PharmIndex;HCI_DataManagement',
|
||||
@in_param_varchar_3 = @errmsg,
|
||||
@in_param_subject = @subject,
|
||||
@in_job_type = 4;
|
||||
|
||||
end
|
||||
|
||||
go
|
||||
|
||||
|
||||
/* step 4 - Update PEXF */
|
||||
declare @cvPHGDPriceCodePEXF int,
|
||||
@SubsidiaryId int,
|
||||
@w_date date
|
||||
|
||||
select @SubsidiaryId = 1000,
|
||||
@cvPHGDPriceCodePEXF = NULL,
|
||||
@w_date = getdate()
|
||||
|
||||
exec arizona.dbo.sp_bmc_Bmc_Applic_Default
|
||||
@in_job_type = 3,
|
||||
@in_param_int_1 = NULL,
|
||||
@in_param_int_2 = @SubsidiaryId,
|
||||
@in_param_varchar_1 = 'cvPHGDPriceCodePSL1',
|
||||
@out_default_value = @cvPHGDPriceCodePEXF output,
|
||||
@out_param_int_1 = null
|
||||
|
||||
|
||||
if @cvPHGDPriceCodePEXF is null
|
||||
begin
|
||||
select @SubsidiaryId = 100
|
||||
|
||||
exec arizona.dbo.sp_bmc_Bmc_Applic_Default
|
||||
@in_job_type = 3,
|
||||
@in_param_int_1 = NULL,
|
||||
@in_param_int_2 = @SubsidiaryId,
|
||||
@in_param_varchar_1 = 'cvPHGDPriceCodePSL1',
|
||||
@out_default_value = @cvPHGDPriceCodePEXF output,
|
||||
@out_param_int_1 = null
|
||||
end
|
||||
|
||||
/*-------------
|
||||
Fermeture des PEXF sans Adresse pour les articles avec insurance code not in (10, 11)
|
||||
------------------*/
|
||||
|
||||
Update top(5000) FP set fp.fp_end_date = DATEADD(d,-1,@w_date)
|
||||
from subsidiary SUB with (nolock)
|
||||
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code not in ('10', '11')
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
|
||||
/*---------------------------------------
|
||||
Clôture du PEXF sans adresse à la date -1 de la start_date du prix PEXF avec adresse
|
||||
pour les articles LS.
|
||||
|
||||
Nous recréons un PEXF avec la bonne start_date et le bon prix afin que la facturation aux caisse maladie soit OK
|
||||
--------------*/
|
||||
|
||||
Update top(5000) FP1 set fp1.fp_end_date = DATEADD(d,-1,fp.FP_start_date)
|
||||
from subsidiary SUB with (nolock)
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is not null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock)
|
||||
where FP2.FP_item = FP.FP_item
|
||||
and FP2.FP_price_code = fp.FP_price_code
|
||||
and FP2.fp_subsidiary = FP.fp_subsidiary
|
||||
and FP2.FP_address is not null
|
||||
and FP2.FP_start_date < GETDATE()
|
||||
and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE()
|
||||
|
||||
order by FP2.FP_start_date desc
|
||||
)
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code in ('10', '11')
|
||||
|
||||
join Fixed_price FP1 with (nolock)
|
||||
on FP1.FP_price_code = prc.price_code_id
|
||||
and FP1.fp_subsidiary = sub.subsidiary_id
|
||||
and FP1.FP_address is null
|
||||
and FP1.FP_start_date < GETDATE()
|
||||
and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP1.FP_item = FP.FP_item
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
and isnull(FP.FP_tax_free_price_per_unit,0) <> isnull(FP1.FP_tax_free_price_per_unit,0)
|
||||
|
||||
/*----------
|
||||
|
||||
Creation PEXF sans adresse avec start_date et prix du PEXF avec Adresse pour LS (Le plus récent)
|
||||
|
||||
------------*/
|
||||
|
||||
declare
|
||||
|
||||
@New_fixed_price_ID int,
|
||||
@nb_fixed_price int ,
|
||||
@fp_subsidiary int,
|
||||
@fp_tariff_type int,
|
||||
@fp_item int,
|
||||
@fp_currency int,
|
||||
@fp_price_code int,
|
||||
@fp_sales_tax_code int,
|
||||
@FP_start_date datetime,
|
||||
@FP_tax_free_price_per_unit dec(14,2)
|
||||
|
||||
|
||||
SELECT @nb_fixed_price = 1
|
||||
|
||||
/*-- Declaration du curseur c_external_item --*/
|
||||
declare c_FP cursor local forward_only read_only static for
|
||||
|
||||
select FP.fp_subsidiary,
|
||||
FP.fp_tariff_type,
|
||||
FP.fp_item,
|
||||
FP.fp_currency,
|
||||
FP.fp_price_code,
|
||||
FP.fp_sales_tax_code,
|
||||
FP.FP_start_date,
|
||||
FP.FP_tax_free_price_per_unit
|
||||
|
||||
from subsidiary SUB with (nolock)
|
||||
|
||||
join price_code PRC with (nolock)
|
||||
on prc.prc_subsidiary = sub.subsidiary_id
|
||||
and prc.price_code_id = @cvPHGDPriceCodePEXF
|
||||
|
||||
join Fixed_price FP with (nolock)
|
||||
on FP.FP_price_code = prc.price_code_id
|
||||
and FP.fp_subsidiary = sub.subsidiary_id
|
||||
and FP.FP_address is not null
|
||||
and FP.FP_start_date < GETDATE()
|
||||
and ISNULL(fp.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP.fixed_price_id = (select top 1 fp2.fixed_price_id from Fixed_price FP2 with (nolock)
|
||||
where FP2.FP_item = FP.FP_item
|
||||
and FP2.FP_price_code = fp.FP_price_code
|
||||
and FP2.fp_subsidiary = FP.fp_subsidiary
|
||||
and FP2.FP_address is not null
|
||||
and FP2.FP_start_date < GETDATE()
|
||||
and ISNULL(FP2.fp_end_date, '2099-12-31') > GETDATE()
|
||||
order by FP2.FP_start_date desc
|
||||
)
|
||||
|
||||
join Item_key ITK with (nolock)
|
||||
on itk.ITK_item = fp.fp_item
|
||||
and ITK.ITK_subsidiary = SUB.Subsidiary_ID
|
||||
and ITK.ITK_type = 1
|
||||
|
||||
join PH_item phit with (nolock)
|
||||
on phit.PHIT_item = ITK.ITK_item
|
||||
and phit.PHIT_insurance_code in ('10', '11')
|
||||
|
||||
left outer join Fixed_price FP1 with (nolock)
|
||||
on FP1.FP_price_code = prc.price_code_id
|
||||
and FP1.fp_subsidiary = sub.subsidiary_id
|
||||
and FP1.FP_address is null
|
||||
and FP1.FP_start_date < GETDATE()
|
||||
and ISNULL(FP1.fp_end_date, '2099-12-31') > GETDATE()
|
||||
and FP1.FP_item = FP.FP_item
|
||||
|
||||
where SUB.subsidiary_id = @SubsidiaryId
|
||||
and FP1.Fixed_price_ID is null
|
||||
|
||||
order by 1
|
||||
|
||||
open c_FP;
|
||||
|
||||
fetch next from c_FP
|
||||
into @fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit
|
||||
|
||||
while (@@fetch_status <> -1 )
|
||||
begin
|
||||
|
||||
if (@@fetch_status <> -2 )
|
||||
begin
|
||||
|
||||
/*----- Recherche dernier ID pour Fixed_Price -----*/
|
||||
select @New_fixed_price_ID = null
|
||||
|
||||
exec sp_bmc_GetNextID
|
||||
@in_key = 'fixed_price',
|
||||
@in_id_column = 'fixed_price_id',
|
||||
@in_nbr_of_record = @nb_fixed_price,
|
||||
@out_id = @New_fixed_price_id output
|
||||
|
||||
insert fixed_price
|
||||
(fixed_price_id,
|
||||
|
||||
fp_subsidiary,
|
||||
fp_tariff_type,
|
||||
fp_item,
|
||||
fp_currency,
|
||||
fp_price_code,
|
||||
fp_sales_tax_code,
|
||||
fp_start_date,
|
||||
fp_tax_free_price_per_unit ,
|
||||
|
||||
fp_unit_code,
|
||||
FP_price_per_unit_unit_code,
|
||||
fp_final_discount_possible,
|
||||
FP_discount_level_1_possible,
|
||||
FP_discount_level_2_possible,
|
||||
FP_origin,
|
||||
FP_remark
|
||||
|
||||
)
|
||||
select
|
||||
@New_fixed_price_id,
|
||||
|
||||
@fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
'Automatic Insert PEXF '
|
||||
|
||||
/*----- fin du curseur -----*/
|
||||
|
||||
|
||||
end /* (@@fetch_status <> -2 ) */
|
||||
|
||||
fetch next from c_FP
|
||||
into @fp_subsidiary ,
|
||||
@fp_tariff_type ,
|
||||
@fp_item ,
|
||||
@fp_currency ,
|
||||
@fp_price_code ,
|
||||
@fp_sales_tax_code ,
|
||||
@FP_start_date ,
|
||||
@FP_tax_free_price_per_unit
|
||||
|
||||
end /* (@@fetch_status <> -1 ) */
|
||||
|
||||
close c_FP;
|
||||
deallocate c_FP;
|
||||
|
||||
ServerName: 'localhost'
|
||||
DatabaseName: 'master'
|
||||
AuthScheme: 'windowsAuthentication'
|
||||
|
||||
- script: echo Hello, world!
|
||||
displayName: 'Run a one-line script'
|
||||
|
||||
- script: |
|
||||
echo Add other tasks to build, test, and deploy your project.
|
||||
echo See https://aka.ms/yaml
|
||||
displayName: 'Run a multi-line script'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "1bb85689-38cd-4f92-89b6-8df1612b1c8f",
|
||||
"prefix": "be",
|
||||
"description": "BEGIN...END block",
|
||||
"body": "BEGIN\r\n $SELECTEDTEXT$$CURSOR$\r\nEND"
|
||||
{
|
||||
"id": "1bb85689-38cd-4f92-89b6-8df1612b1c8f",
|
||||
"prefix": "be",
|
||||
"description": "BEGIN...END block",
|
||||
"body": "BEGIN\r\n $SELECTEDTEXT$$CURSOR$\r\nEND"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "9bbe2292-2584-4d65-a484-4f60dc92cd94",
|
||||
"prefix": "bkpHist",
|
||||
"description": "list database backup history",
|
||||
"body": ";WITH cteHist AS (\r\n SELECT [ibs].[database_name], [ibs].[backup_start_date], [ibs].[backup_finish_date], ROW_NUMBER()OVER(PARTITION BY [ibs].[database_name] ORDER BY [ibs].[backup_finish_date] DESC ) AS rnk\r\n FROM msdb.dbo.backupset ibs \r\n WHERE [ibs].[type]='D'\r\n)\r\n, ctehistFilt AS (\r\nSELECT *\r\nFROM [cteHist]\r\n--WHERE [cteHist].[rnk] <= 10\r\nWHERE [cteHist].[backup_finish_date] >= DATEADD(DAY, -7, CURRENT_TIMESTAMP)\r\n)\r\n\r\nSELECT \r\n d.name\r\n --,[last 5 backups] = STUFF(CONVERT(VARCHAR(MAX),bkp.strDates),1,1,'')\r\n ,h.[backup_finish_date]\r\n ,h.[rnk] AS position\r\n ,d.collation_name\r\n ,d.compatibility_level\r\nFROM sys.databases d\r\n JOIN [ctehistFilt] h ON h.[database_name] = d.[name]\r\nWHERE 1=1\r\nAND d.name NOT IN (\r\n 'master'\r\n ,'model'\r\n ,'tempdb'\r\n ,'msdb'\r\n)\r\n"
|
||||
{
|
||||
"id": "9bbe2292-2584-4d65-a484-4f60dc92cd94",
|
||||
"prefix": "bkpHist",
|
||||
"description": "list database backup history",
|
||||
"body": ";WITH cteHist AS (\r\n SELECT [ibs].[database_name], [ibs].[backup_start_date], [ibs].[backup_finish_date], ROW_NUMBER()OVER(PARTITION BY [ibs].[database_name] ORDER BY [ibs].[backup_finish_date] DESC ) AS rnk\r\n FROM msdb.dbo.backupset ibs \r\n WHERE [ibs].[type]='D'\r\n)\r\n, ctehistFilt AS (\r\nSELECT *\r\nFROM [cteHist]\r\n--WHERE [cteHist].[rnk] <= 10\r\nWHERE [cteHist].[backup_finish_date] >= DATEADD(DAY, -7, CURRENT_TIMESTAMP)\r\n)\r\n\r\nSELECT \r\n d.name\r\n --,[last 5 backups] = STUFF(CONVERT(VARCHAR(MAX),bkp.strDates),1,1,'')\r\n ,h.[backup_finish_date]\r\n ,h.[rnk] AS position\r\n ,d.collation_name\r\n ,d.compatibility_level\r\nFROM sys.databases d\r\n JOIN [ctehistFilt] h ON h.[database_name] = d.[name]\r\nWHERE 1=1\r\nAND d.name NOT IN (\r\n 'master'\r\n ,'model'\r\n ,'tempdb'\r\n ,'msdb'\r\n)\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "cc7bffa0-701b-4bb2-9a9c-090d9646a93e",
|
||||
"prefix": "bkp_apo",
|
||||
"description": "backup activepos_read and wait for the job to finish",
|
||||
"body": "SET XACT_ABORT ON \r\nDECLARE @pos2 sysname;\r\n\r\nSELECT @pos2 = POS_hostname\r\nFROM Arizona.dbo.Point_of_sale\r\nWHERE POS_number = 2;\r\n\r\nBEGIN TRY\r\n EXEC sys.sp_testlinkedserver @pos2\r\n\r\n --start backup\r\n EXEC msdb.dbo.sp_start_job @job_name = N'D91030 - Backup ActivePos_Read' , @step_name = 'Purge old ActivePos_Read backups'\r\n\r\n WAITFOR DELAY '00:00:05.000'\r\n\r\n WHILE EXISTS(\r\n SELECT sj.name\r\n , sja.*\r\n FROM msdb.dbo.sysjobactivity AS sja\r\n INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id\r\n WHERE sj.[name]='D91030 - Backup ActivePos_Read'\r\n AND sja.start_execution_date IS NOT NULL\r\n AND sja.stop_execution_date IS NULL\r\n ) BEGIN\r\n --PRINT 'job is still running '+CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n DECLARE @t VARCHAR(20) = CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n RAISERROR('%s, job is still running', 0, 1, @t) WITH NOWAIT;\r\n WAITFOR DELAY '00:00:05.000'\r\n END \r\n \r\n --last status\r\n SELECT\r\n JobName = J.name,\r\n H.*\r\n FROM\r\n msdb.dbo.sysjobs AS J\r\n CROSS APPLY (\r\n SELECT TOP 20\r\n JobName = J.name,\r\n StepNumber = T.step_id,\r\n StepName = T.step_name,\r\n StepStatus = CASE T.run_status\r\n WHEN 0 THEN 'Failed'\r\n WHEN 1 THEN 'Succeeded'\r\n WHEN 2 THEN 'Retry'\r\n WHEN 3 THEN 'Canceled'\r\n ELSE 'Running' END,\r\n ExecutedAt = msdb.dbo.agent_datetime(T.run_date, T.run_time),\r\n ExecutingHours = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) / 60,\r\n ExecutingMinutes = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) % 60,\r\n Message = T.message\r\n ,t.[instance_id]\r\n FROM msdb.dbo.sysjobhistory AS T\r\n WHERE T.job_id = J.job_id\r\n ORDER BY t.[instance_id] DESC\r\n ) AS H\r\n WHERE [J].[name]='D91030 - Backup ActivePos_Read'\r\n AND [H].[StepNumber] = 0\r\n ORDER BY J.name\r\n\r\n\r\nEND TRY\r\nBEGIN CATCH\r\n PRINT ERROR_MESSAGE()\r\n RAISERROR('pos %s is not reachable', 16, 2, @pos2)\r\nEND CATCH\r\n"
|
||||
{
|
||||
"id": "cc7bffa0-701b-4bb2-9a9c-090d9646a93e",
|
||||
"prefix": "bkp_apo",
|
||||
"description": "backup activepos_read and wait for the job to finish",
|
||||
"body": "SET XACT_ABORT ON \r\nDECLARE @pos2 sysname;\r\n\r\nSELECT @pos2 = POS_hostname\r\nFROM Arizona.dbo.Point_of_sale\r\nWHERE POS_number = 2;\r\n\r\nBEGIN TRY\r\n EXEC sys.sp_testlinkedserver @pos2\r\n\r\n --start backup\r\n EXEC msdb.dbo.sp_start_job @job_name = N'D91030 - Backup ActivePos_Read' , @step_name = 'Purge old ActivePos_Read backups'\r\n\r\n WAITFOR DELAY '00:00:05.000'\r\n\r\n WHILE EXISTS(\r\n SELECT sj.name\r\n , sja.*\r\n FROM msdb.dbo.sysjobactivity AS sja\r\n INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id\r\n WHERE sj.[name]='D91030 - Backup ActivePos_Read'\r\n AND sja.start_execution_date IS NOT NULL\r\n AND sja.stop_execution_date IS NULL\r\n ) BEGIN\r\n --PRINT 'job is still running '+CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n DECLARE @t VARCHAR(20) = CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n RAISERROR('%s, job is still running', 0, 1, @t) WITH NOWAIT;\r\n WAITFOR DELAY '00:00:05.000'\r\n END \r\n \r\n --last status\r\n SELECT\r\n JobName = J.name,\r\n H.*\r\n FROM\r\n msdb.dbo.sysjobs AS J\r\n CROSS APPLY (\r\n SELECT TOP 20\r\n JobName = J.name,\r\n StepNumber = T.step_id,\r\n StepName = T.step_name,\r\n StepStatus = CASE T.run_status\r\n WHEN 0 THEN 'Failed'\r\n WHEN 1 THEN 'Succeeded'\r\n WHEN 2 THEN 'Retry'\r\n WHEN 3 THEN 'Canceled'\r\n ELSE 'Running' END,\r\n ExecutedAt = msdb.dbo.agent_datetime(T.run_date, T.run_time),\r\n ExecutingHours = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) / 60,\r\n ExecutingMinutes = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) % 60,\r\n Message = T.message\r\n ,t.[instance_id]\r\n FROM msdb.dbo.sysjobhistory AS T\r\n WHERE T.job_id = J.job_id\r\n ORDER BY t.[instance_id] DESC\r\n ) AS H\r\n WHERE [J].[name]='D91030 - Backup ActivePos_Read'\r\n AND [H].[StepNumber] = 0\r\n ORDER BY J.name\r\n\r\n\r\nEND TRY\r\nBEGIN CATCH\r\n PRINT ERROR_MESSAGE()\r\n RAISERROR('pos %s is not reachable', 16, 2, @pos2)\r\nEND CATCH\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "c867233c-3e25-49a8-b4e9-94c8dc11bdb0",
|
||||
"prefix": "bt",
|
||||
"description": "Begin transaction",
|
||||
"body": "BEGIN TRANSACTION "
|
||||
{
|
||||
"id": "c867233c-3e25-49a8-b4e9-94c8dc11bdb0",
|
||||
"prefix": "bt",
|
||||
"description": "Begin transaction",
|
||||
"body": "BEGIN TRANSACTION "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ca9ed7a3-6fb0-4d39-b918-887951161076",
|
||||
"prefix": "cal",
|
||||
"description": "create a calendar #cal table",
|
||||
"body": "DECLARE @dtmFrom DATETIME, @dtmTo DATETIME;\r\nSELECT @dtmFrom = '20100812', @dtmTo=CURRENT_TIMESTAMP\r\n\r\n--#region create calendar\r\nDECLARE @nb TABLE( val INT);\r\nINSERT INTO @nb(val)\r\nSELECT a=0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9;\r\n\r\nIF (SELECT OBJECT_ID('tempdb..#cal'))IS NOT NULL BEGIN\r\n\tDROP TABLE #cal;\r\nEND; \r\n\r\nSELECT \r\n --+1 to take the current day, must be reflected in the TOP subquery\r\n DATEADD(DAY, (x.[nbr] * -1) + 1, CURRENT_TIMESTAMP) AS dt\r\nINTO #cal\r\nFROM(\r\n SELECT * \r\n FROM (\r\n --the TOP limits the calendar to the specified days. +1 to compensate the current day in DATEADD()\r\n SELECT TOP (DATEDIFF(DAY, @dtmFrom, @dtmTo)+1)\r\n ROW_NUMBER()OVER(ORDER BY a.val) AS nbr\r\n FROM @nb a\r\n CROSS JOIN @nb b\r\n CROSS JOIN @nb c\r\n CROSS JOIN @nb d\r\n CROSS JOIN @nb e\r\n CROSS JOIN @nb f\r\n ORDER BY a.[val]\r\n )tally\r\n)x\r\n--#endregion\r\n\r\nSELECT MIN([c].[dt]), MAX([c].[dt])\r\nFROM [#cal] c"
|
||||
{
|
||||
"id": "ca9ed7a3-6fb0-4d39-b918-887951161076",
|
||||
"prefix": "cal",
|
||||
"description": "create a calendar #cal table",
|
||||
"body": "DECLARE @dtmFrom DATETIME, @dtmTo DATETIME;\r\nSELECT @dtmFrom = '20100812', @dtmTo=CURRENT_TIMESTAMP\r\n\r\n--#region create calendar\r\nDECLARE @nb TABLE( val INT);\r\nINSERT INTO @nb(val)\r\nSELECT a=0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9;\r\n\r\nIF (SELECT OBJECT_ID('tempdb..#cal'))IS NOT NULL BEGIN\r\n\tDROP TABLE #cal;\r\nEND; \r\n\r\nSELECT \r\n --+1 to take the current day, must be reflected in the TOP subquery\r\n DATEADD(DAY, (x.[nbr] * -1) + 1, CURRENT_TIMESTAMP) AS dt\r\nINTO #cal\r\nFROM(\r\n SELECT * \r\n FROM (\r\n --the TOP limits the calendar to the specified days. +1 to compensate the current day in DATEADD()\r\n SELECT TOP (DATEDIFF(DAY, @dtmFrom, @dtmTo)+1)\r\n ROW_NUMBER()OVER(ORDER BY a.val) AS nbr\r\n FROM @nb a\r\n CROSS JOIN @nb b\r\n CROSS JOIN @nb c\r\n CROSS JOIN @nb d\r\n CROSS JOIN @nb e\r\n CROSS JOIN @nb f\r\n ORDER BY a.[val]\r\n )tally\r\n)x\r\n--#endregion\r\n\r\nSELECT MIN([c].[dt]), MAX([c].[dt])\r\nFROM [#cal] c"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "f1d3df2e-22bf-4a1e-b423-72b3fb610932",
|
||||
"prefix": "cc",
|
||||
"description": "comment",
|
||||
"body": "/* $CURSOR$ */"
|
||||
{
|
||||
"id": "f1d3df2e-22bf-4a1e-b423-72b3fb610932",
|
||||
"prefix": "cc",
|
||||
"description": "comment",
|
||||
"body": "/* $CURSOR$ */"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ef7f7e95-0173-4c0a-b540-65616077d483",
|
||||
"prefix": "check_amr",
|
||||
"description": "check recorded amr by connectic and max current amr",
|
||||
"body": "SELECT s.*, a.APS_monitor_row_ID, a.AMR_APS_TS\r\nFROM ActiveSystemServer.amr.MonitorRowsStatus s\r\n LEFT JOIN Arizona.dbo.APS_monitor_row a ON a.APS_monitor_row_ID = s.LastTreatedMonitorRow\r\nWHERE s.DatabaseName='arizona'\r\n\r\nSELECT MAX(a.APS_monitor_row_ID)\r\nFROM Arizona.dbo.APS_monitor_row a \r\n"
|
||||
{
|
||||
"id": "ef7f7e95-0173-4c0a-b540-65616077d483",
|
||||
"prefix": "check_amr",
|
||||
"description": "check recorded amr by connectic and max current amr",
|
||||
"body": "SELECT s.*, a.APS_monitor_row_ID, a.AMR_APS_TS\r\nFROM ActiveSystemServer.amr.MonitorRowsStatus s\r\n LEFT JOIN Arizona.dbo.APS_monitor_row a ON a.APS_monitor_row_ID = s.LastTreatedMonitorRow\r\nWHERE s.DatabaseName='arizona'\r\n\r\nSELECT MAX(a.APS_monitor_row_ID)\r\nFROM Arizona.dbo.APS_monitor_row a \r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "0eb1ed81-6410-464e-aec4-3580bef84fa4",
|
||||
"prefix": "check_critical_jobs",
|
||||
"description": "Populate smsJobCheck with the next schedule the syncro HIV should run",
|
||||
"body": "/*============================================================================= \r\n\r\nPopulate smsJobCheck with the next schedule the syncro HIV should run\r\nExtracted FROM [mon].[Check_Critical_Job]\r\n\r\nCreation : 17.05.2023 / TSC\r\nModifications:\r\n\r\n=============================================================================*/ \r\nIF EXISTS (\r\n SELECT 1 \r\n FROM [HCITools].[mon].[SMSJobCheck] a\r\n WHERE [a].[SJCNextExecution] IS NULL \r\n)\r\nBEGIN \r\n UPDATE sjc\r\n SET [sjc].[SJCNextExecution] = [sja].[next_scheduled_run_date]\r\n FROM HCITools.[mon].SMSJobCheck sjc\r\n INNER JOIN msdb.dbo.sysjobsteps sjs WITH (NOLOCK)\r\n ON [sjs].[step_name] LIKE '%Start job %' + [sjc].[SJCJobName] + '%'\r\n INNER JOIN msdb.dbo.sysjobs sj WITH (NOLOCK)\r\n ON sjs.job_id = sj.job_id\r\n INNER JOIN msdb.dbo.sysjobactivity sja WITH (NOLOCK)\r\n ON sja.job_id = sj.job_id\r\n INNER JOIN msdb.dbo.syssessions AS sse\r\n ON sja.session_id = sse.session_id\r\n INNER JOIN\r\n (\r\n SELECT MAX(agent_start_date) AS agent_start_date\r\n FROM msdb.dbo.syssessions\r\n ) AS mss\r\n ON sse.agent_start_date = mss.agent_start_date\r\n WHERE ISNULL([sja].[start_execution_date], GETDATE()-1) >= ISNULL([sjc].[SJCNextExecution], GETDATE() - 1);\r\nEND \r\n\r\nEXEC msdb.dbo.sp_stop_job\r\n @job_name = 'D92220 - Check Critical Jobs'"
|
||||
{
|
||||
"id": "0eb1ed81-6410-464e-aec4-3580bef84fa4",
|
||||
"prefix": "check_critical_jobs",
|
||||
"description": "Populate smsJobCheck with the next schedule the syncro HIV should run",
|
||||
"body": "/*============================================================================= \r\n\r\nPopulate smsJobCheck with the next schedule the syncro HIV should run\r\nExtracted FROM [mon].[Check_Critical_Job]\r\n\r\nCreation : 17.05.2023 / TSC\r\nModifications:\r\n\r\n=============================================================================*/ \r\nIF EXISTS (\r\n SELECT 1 \r\n FROM [HCITools].[mon].[SMSJobCheck] a\r\n WHERE [a].[SJCNextExecution] IS NULL \r\n)\r\nBEGIN \r\n UPDATE sjc\r\n SET [sjc].[SJCNextExecution] = [sja].[next_scheduled_run_date]\r\n FROM HCITools.[mon].SMSJobCheck sjc\r\n INNER JOIN msdb.dbo.sysjobsteps sjs WITH (NOLOCK)\r\n ON [sjs].[step_name] LIKE '%Start job %' + [sjc].[SJCJobName] + '%'\r\n INNER JOIN msdb.dbo.sysjobs sj WITH (NOLOCK)\r\n ON sjs.job_id = sj.job_id\r\n INNER JOIN msdb.dbo.sysjobactivity sja WITH (NOLOCK)\r\n ON sja.job_id = sj.job_id\r\n INNER JOIN msdb.dbo.syssessions AS sse\r\n ON sja.session_id = sse.session_id\r\n INNER JOIN\r\n (\r\n SELECT MAX(agent_start_date) AS agent_start_date\r\n FROM msdb.dbo.syssessions\r\n ) AS mss\r\n ON sse.agent_start_date = mss.agent_start_date\r\n WHERE ISNULL([sja].[start_execution_date], GETDATE()-1) >= ISNULL([sjc].[SJCNextExecution], GETDATE() - 1);\r\nEND \r\n\r\nEXEC msdb.dbo.sp_stop_job\r\n @job_name = 'D92220 - Check Critical Jobs'"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "d51f5094-34a8-4d58-804f-b9e2e535e5f7",
|
||||
"prefix": "check_mail_log",
|
||||
"description": "list entries from dbmail that had an error",
|
||||
"body": "SELECT \r\n l.[log_id]\r\n ,l.[log_date]\r\n ,l.[description]\r\n ,i.[mailitem_id]\r\n ,i.[recipients]\r\n ,i.[subject]\r\n ,i.[body]\r\nFROM msdb.dbo.[sysmail_log] l\r\n JOIN msdb.dbo.[sysmail_allitems] i ON i.[mailitem_id]=l.[mailitem_id]"
|
||||
{
|
||||
"id": "d51f5094-34a8-4d58-804f-b9e2e535e5f7",
|
||||
"prefix": "check_mail_log",
|
||||
"description": "list entries from dbmail that had an error",
|
||||
"body": "SELECT \r\n l.[log_id]\r\n ,l.[log_date]\r\n ,l.[description]\r\n ,i.[mailitem_id]\r\n ,i.[recipients]\r\n ,i.[subject]\r\n ,i.[body]\r\nFROM msdb.dbo.[sysmail_log] l\r\n JOIN msdb.dbo.[sysmail_allitems] i ON i.[mailitem_id]=l.[mailitem_id]"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "1dde3f7e-53f0-49e2-a02d-c2fc7258a338",
|
||||
"prefix": "check_upload_mig_pharma",
|
||||
"description": "check l'avancée de l'upload des données agitées lors d'une migration depuis la pharmacie",
|
||||
"body": "USE [Arizona];\r\nGO\r\nDECLARE @tot INT = 131715\r\n\r\nSELECT COUNT(*) AS [left], @tot AS [total], ROUND(100-(100.0*COUNT(1)/@tot), 2) AS [percent done], ROUND(100.0*COUNT(1)/@tot,2) AS [percent left]\r\n FROM APS_monitor_row amr WITH (NOLOCK)\r\n JOIN APS_monitor_table amt WITH (NOLOCK)\r\n ON amt.APS_monitor_table_ID = amr.AMR_APS_monitor_table\r\n AND amt.AMT_table_name IN ('address', 'PH_insurance_card', 'ph_patient', 'Address_key')\r\n WHERE amr.AMR_ArizonaRep_extraction_TS IS NULL;\r\n GO\r\n\r\n USE [Arizona];\r\nGO\r\n\r\nDECLARE @tot INT = 111279\r\n\r\nSELECT COUNT(*) AS [left], @tot AS [total], ROUND(100-(100.0*COUNT(1)/@tot), 2) AS [percent done], ROUND(100.0*COUNT(1)/@tot,2) AS [percent left]\r\n FROM APS_monitor_row amr WITH (NOLOCK)\r\n JOIN APS_monitor_table amt WITH (NOLOCK)\r\n ON amt.APS_monitor_table_ID = amr.AMR_APS_monitor_table\r\n AND amt.AMT_table_name IN ('Document_header')\r\n WHERE amr.AMR_ArizonaRep_extraction_TS IS NULL;\r\n GO"
|
||||
{
|
||||
"id": "1dde3f7e-53f0-49e2-a02d-c2fc7258a338",
|
||||
"prefix": "check_upload_mig_pharma",
|
||||
"description": "check l'avancée de l'upload des données agitées lors d'une migration depuis la pharmacie",
|
||||
"body": "USE [Arizona];\r\nGO\r\nDECLARE @tot INT = 131715\r\n\r\nSELECT COUNT(*) AS [left], @tot AS [total], ROUND(100-(100.0*COUNT(1)/@tot), 2) AS [percent done], ROUND(100.0*COUNT(1)/@tot,2) AS [percent left]\r\n FROM APS_monitor_row amr WITH (NOLOCK)\r\n JOIN APS_monitor_table amt WITH (NOLOCK)\r\n ON amt.APS_monitor_table_ID = amr.AMR_APS_monitor_table\r\n AND amt.AMT_table_name IN ('address', 'PH_insurance_card', 'ph_patient', 'Address_key')\r\n WHERE amr.AMR_ArizonaRep_extraction_TS IS NULL;\r\n GO\r\n\r\n USE [Arizona];\r\nGO\r\n\r\nDECLARE @tot INT = 111279\r\n\r\nSELECT COUNT(*) AS [left], @tot AS [total], ROUND(100-(100.0*COUNT(1)/@tot), 2) AS [percent done], ROUND(100.0*COUNT(1)/@tot,2) AS [percent left]\r\n FROM APS_monitor_row amr WITH (NOLOCK)\r\n JOIN APS_monitor_table amt WITH (NOLOCK)\r\n ON amt.APS_monitor_table_ID = amr.AMR_APS_monitor_table\r\n AND amt.AMT_table_name IN ('Document_header')\r\n WHERE amr.AMR_ArizonaRep_extraction_TS IS NULL;\r\n GO"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "2a256de1-a831-4337-a883-7ee540cb4563",
|
||||
"prefix": "chk",
|
||||
"description": "Creates an extended event session, runs the code you want to test, extracts the output and then stops the session",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2018\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/testing-performance-individual-sql-statements-within-batch-using-sql-prompt\r\n**/\r\n\r\nIF EXISTS --if the session already exists, then delete it. We are assuming you've changed something\r\n (\r\n SELECT * FROM sys.server_event_sessions\r\n WHERE server_event_sessions.name = 'CheckingSQLStatements'\r\n )\r\n DROP EVENT SESSION CheckingSQLStatements ON SERVER;\r\nGO\r\nCREATE EVENT SESSION CheckingSQLStatements --call it what you wish, of course\r\nON SERVER\r\n ADD EVENT sqlserver.sql_statement_completed --we just have one event\r\n (ACTION (sqlserver.database_name, sqlserver.sql_text, sqlserver.plan_handle)-- and these global vars\r\n WHERE (sqlserver.like_i_sql_unicode_string(sqlserver.sql_text, N'--Test these queries%'))\r\n\t --we just want the batch and nothing else so we put an identifying string at the start\r\n )\r\n ADD TARGET package0.ring_buffer \r\n --we don't need a more permanent record or a bucket count\r\nWITH (STARTUP_STATE = OFF);\r\nGO\r\nALTER EVENT SESSION CheckingSQLStatements ON SERVER STATE = START;\r\n--V-----The Batch being tested starts here ------V\r\nGO --don't change this next line without changing the WHERE clause above\r\n--Test these queries\r\n-------------------------------------------------------------------\r\n\r\n$SELECTEDTEXT$\r\n\r\n------------------------------------------------------------------\r\ngo\r\nDECLARE @Target_Data XML =\r\n (\r\n SELECT TOP 1 Cast(xet.target_data AS XML) AS targetdata\r\n FROM sys.dm_xe_session_targets AS xet\r\n INNER JOIN sys.dm_xe_sessions AS xes\r\n ON xes.address = xet.event_session_address\r\n WHERE xes.name = 'CheckingSQLStatements'\r\n AND xet.target_name = 'ring_buffer'\r\n );\r\nSELECT \r\nCONVERT(datetime2,\r\n SwitchOffset(CONVERT(datetimeoffset,the.event_data.value('(@timestamp)[1]', 'datetime2')),\r\n\t\tDateName(TzOffset, SYSDATETIMEOFFSET()))) AS datetime_local,\r\nCONVERT(DECIMAL(6,3),round(the.event_data.value('(data[@name=\"duration\"]/value)[1]', 'bigint')/1000000.0,3,1)) AS duration,\r\nthe.event_data.value('(data[@name=\"statement\"]/value)[1]', 'nvarchar(max)') AS [statement],\r\n--the.event_data.value('(action[@name=\"sql_text\"]/value)[1]', 'nvarchar(max)') AS sql_text,\r\n--the.event_data.value('(action[@name=\"database_name\"]/value)[1]', 'nvarchar(80)') AS [database_name],\r\nqp.query_plan,\r\nthe.event_data.value('(data[@name=\"cpu_time\"]/value)[1]', 'bigint') AS [cpu_time(microsSecs)],\r\nthe.event_data.value('(data[@name=\"physical_reads\"]/value)[1]', 'bigint') AS physical_reads,\r\nthe.event_data.value('(data[@name=\"logical_reads\"]/value)[1]', 'bigint') AS logical_reads,\r\nthe.event_data.value('(data[@name=\"writes\"]/value)[1]', 'bigint') AS writes,\r\nthe.event_data.value('(data[@name=\"row_count\"]/value)[1]', 'bigint') AS row_count\r\n--the.event_data.value('(data[@name=\"last_row_count\"]/value)[1]', 'int') AS last_row_count,\r\n--the.event_data.value('(data[@name=\"line_number\"]/value)[1]', 'int') AS line_number,\r\n--the.event_data.value('(data[@name=\"offset\"]/value)[1]', 'int') AS offset,\r\n--the.event_data.value('(data[@name=\"offset_end\"]/value)[1]', 'int') AS offset_end,\r\n\r\nFROM @Target_Data.nodes('//RingBufferTarget/event') AS the (event_data)\r\n CROSS APPLY sys.dm_exec_query_plan(\r\n Convert(varbinary(64),--convert to valid plan handle\r\n '0x' + the.event_data.value('(action[@name=\"plan_handle\"]/value)[1]', 'nvarchar(max)')\r\n\t\t ,1)) as qp\r\n\r\nALTER EVENT SESSION CheckingSQLStatements ON SERVER STATE = STOP;"
|
||||
{
|
||||
"id": "2a256de1-a831-4337-a883-7ee540cb4563",
|
||||
"prefix": "chk",
|
||||
"description": "Creates an extended event session, runs the code you want to test, extracts the output and then stops the session",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2018\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/testing-performance-individual-sql-statements-within-batch-using-sql-prompt\r\n**/\r\n\r\nIF EXISTS --if the session already exists, then delete it. We are assuming you've changed something\r\n (\r\n SELECT * FROM sys.server_event_sessions\r\n WHERE server_event_sessions.name = 'CheckingSQLStatements'\r\n )\r\n DROP EVENT SESSION CheckingSQLStatements ON SERVER;\r\nGO\r\nCREATE EVENT SESSION CheckingSQLStatements --call it what you wish, of course\r\nON SERVER\r\n ADD EVENT sqlserver.sql_statement_completed --we just have one event\r\n (ACTION (sqlserver.database_name, sqlserver.sql_text, sqlserver.plan_handle)-- and these global vars\r\n WHERE (sqlserver.like_i_sql_unicode_string(sqlserver.sql_text, N'--Test these queries%'))\r\n\t --we just want the batch and nothing else so we put an identifying string at the start\r\n )\r\n ADD TARGET package0.ring_buffer \r\n --we don't need a more permanent record or a bucket count\r\nWITH (STARTUP_STATE = OFF);\r\nGO\r\nALTER EVENT SESSION CheckingSQLStatements ON SERVER STATE = START;\r\n--V-----The Batch being tested starts here ------V\r\nGO --don't change this next line without changing the WHERE clause above\r\n--Test these queries\r\n-------------------------------------------------------------------\r\n\r\n$SELECTEDTEXT$\r\n\r\n------------------------------------------------------------------\r\ngo\r\nDECLARE @Target_Data XML =\r\n (\r\n SELECT TOP 1 Cast(xet.target_data AS XML) AS targetdata\r\n FROM sys.dm_xe_session_targets AS xet\r\n INNER JOIN sys.dm_xe_sessions AS xes\r\n ON xes.address = xet.event_session_address\r\n WHERE xes.name = 'CheckingSQLStatements'\r\n AND xet.target_name = 'ring_buffer'\r\n );\r\nSELECT \r\nCONVERT(datetime2,\r\n SwitchOffset(CONVERT(datetimeoffset,the.event_data.value('(@timestamp)[1]', 'datetime2')),\r\n\t\tDateName(TzOffset, SYSDATETIMEOFFSET()))) AS datetime_local,\r\nCONVERT(DECIMAL(6,3),round(the.event_data.value('(data[@name=\"duration\"]/value)[1]', 'bigint')/1000000.0,3,1)) AS duration,\r\nthe.event_data.value('(data[@name=\"statement\"]/value)[1]', 'nvarchar(max)') AS [statement],\r\n--the.event_data.value('(action[@name=\"sql_text\"]/value)[1]', 'nvarchar(max)') AS sql_text,\r\n--the.event_data.value('(action[@name=\"database_name\"]/value)[1]', 'nvarchar(80)') AS [database_name],\r\nqp.query_plan,\r\nthe.event_data.value('(data[@name=\"cpu_time\"]/value)[1]', 'bigint') AS [cpu_time(microsSecs)],\r\nthe.event_data.value('(data[@name=\"physical_reads\"]/value)[1]', 'bigint') AS physical_reads,\r\nthe.event_data.value('(data[@name=\"logical_reads\"]/value)[1]', 'bigint') AS logical_reads,\r\nthe.event_data.value('(data[@name=\"writes\"]/value)[1]', 'bigint') AS writes,\r\nthe.event_data.value('(data[@name=\"row_count\"]/value)[1]', 'bigint') AS row_count\r\n--the.event_data.value('(data[@name=\"last_row_count\"]/value)[1]', 'int') AS last_row_count,\r\n--the.event_data.value('(data[@name=\"line_number\"]/value)[1]', 'int') AS line_number,\r\n--the.event_data.value('(data[@name=\"offset\"]/value)[1]', 'int') AS offset,\r\n--the.event_data.value('(data[@name=\"offset_end\"]/value)[1]', 'int') AS offset_end,\r\n\r\nFROM @Target_Data.nodes('//RingBufferTarget/event') AS the (event_data)\r\n CROSS APPLY sys.dm_exec_query_plan(\r\n Convert(varbinary(64),--convert to valid plan handle\r\n '0x' + the.event_data.value('(action[@name=\"plan_handle\"]/value)[1]', 'nvarchar(max)')\r\n\t\t ,1)) as qp\r\n\r\nALTER EVENT SESSION CheckingSQLStatements ON SERVER STATE = STOP;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "284b1bd2-268f-4a55-9ba4-3e5eea6bf9ba",
|
||||
"prefix": "cj",
|
||||
"description": "CROSS JOIN fragment",
|
||||
"body": "CROSS JOIN "
|
||||
{
|
||||
"id": "284b1bd2-268f-4a55-9ba4-3e5eea6bf9ba",
|
||||
"prefix": "cj",
|
||||
"description": "CROSS JOIN fragment",
|
||||
"body": "CROSS JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "f5116e48-dbe8-4e51-8628-e4dc235bdb5a",
|
||||
"prefix": "class_add",
|
||||
"description": "add classification to a column",
|
||||
"body": "ADD SENSITIVITY CLASSIFICATION TO $CURSOR$ WITH ( LABEL='Confidential', INFORMATION_TYPE='Galenica Used Personal Informations', RANK=High );"
|
||||
{
|
||||
"id": "f5116e48-dbe8-4e51-8628-e4dc235bdb5a",
|
||||
"prefix": "class_add",
|
||||
"description": "add classification to a column",
|
||||
"body": "ADD SENSITIVITY CLASSIFICATION TO $CURSOR$ WITH ( LABEL='Confidential', INFORMATION_TYPE='Galenica Used Personal Informations', RANK=High );"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "d21e6640-4e55-42d2-9035-f291e0f4c18d",
|
||||
"prefix": "commvault_tpl",
|
||||
"description": "",
|
||||
"body": "/* \r\nSee https://galenica.atlassian.net/wiki/spaces/DBA/pages/247567427/CMD+-+Backup+and+Restore+with+CLR+and+SP+in+HCITools\r\nfor example how to use the CLR\r\n*/\r\nDECLARE @password varchar(255)\r\nSET @password = HCITools.dbo.fn_Decrypt(\r\n0x01000000C2811DD6D0339FF2EFE6AE1181B3469D18798020836E3E0A1E4BC96D548B4FCDFFB77F264E1A4F42AD91F785284A6F5D4F3E533B0355E88F91A61E7E671472D3F580FC36CCF0AE48858099190C1B7E3A1A2A292A3E8809B40EAB6EAECF3C0FF6871CAF54A3928615C21830602BCB12F1F973E4B4B1F34A613B342C397372596025DB62CB426319AE916D0DC5CCAED8A62675D7602D592A92);\r\n"
|
||||
{
|
||||
"id": "d21e6640-4e55-42d2-9035-f291e0f4c18d",
|
||||
"prefix": "commvault_tpl",
|
||||
"description": "",
|
||||
"body": "/* \r\nSee https://galenica.atlassian.net/wiki/spaces/DBA/pages/247567427/CMD+-+Backup+and+Restore+with+CLR+and+SP+in+HCITools\r\nfor example how to use the CLR\r\n*/\r\nDECLARE @password varchar(255)\r\nSET @password = HCITools.dbo.fn_Decrypt(\r\n0x01000000C2811DD6D0339FF2EFE6AE1181B3469D18798020836E3E0A1E4BC96D548B4FCDFFB77F264E1A4F42AD91F785284A6F5D4F3E533B0355E88F91A61E7E671472D3F580FC36CCF0AE48858099190C1B7E3A1A2A292A3E8809B40EAB6EAECF3C0FF6871CAF54A3928615C21830602BCB12F1F973E4B4B1F34A613B342C397372596025DB62CB426319AE916D0DC5CCAED8A62675D7602D592A92);\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ccd61e56-ded6-427a-9bd7-24200486cb1d",
|
||||
"prefix": "crs_start",
|
||||
"description": "start crs logreader agent",
|
||||
"body": "EXEC msdb.dbo.sp_start_job @job_name = N'DR00500 - Arizona Log reader' , @step_name = 'Log Reader Agent startup message.'"
|
||||
{
|
||||
"id": "ccd61e56-ded6-427a-9bd7-24200486cb1d",
|
||||
"prefix": "crs_start",
|
||||
"description": "start crs logreader agent",
|
||||
"body": "EXEC msdb.dbo.sp_start_job @job_name = N'DR00500 - Arizona Log reader' , @step_name = 'Log Reader Agent startup message.'"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "692a606f-2cae-42d9-9f7a-587bb5c6d4bd",
|
||||
"prefix": "ct",
|
||||
"description": "Commit transaction",
|
||||
"body": "COMMIT TRANSACTION "
|
||||
{
|
||||
"id": "692a606f-2cae-42d9-9f7a-587bb5c6d4bd",
|
||||
"prefix": "ct",
|
||||
"description": "Commit transaction",
|
||||
"body": "COMMIT TRANSACTION "
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"id": "84019c93-ac72-47eb-a7ce-9fccf91bd020",
|
||||
"prefix": "curff",
|
||||
"description": "Fast-forward read-only cursor",
|
||||
"body": "/* declare variables */\r\nDECLARE @variable INT\r\n\r\nDECLARE $cursor_name$ CURSOR FAST_FORWARD READ_ONLY FOR $select_statement$\r\n\r\nOPEN $cursor_name$\r\n\r\nFETCH NEXT FROM $cursor_name$ INTO @variable\r\n\r\nWHILE @@FETCH_STATUS = 0\r\nBEGIN\r\n $CURSOR$\r\n\r\n FETCH NEXT FROM $cursor_name$ INTO @variable\r\nEND\r\n\r\nCLOSE $cursor_name$\r\nDEALLOCATE $cursor_name$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cursor_name",
|
||||
"defaultValue": ""
|
||||
},
|
||||
{
|
||||
"name": "select_statement",
|
||||
"defaultValue": ""
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "84019c93-ac72-47eb-a7ce-9fccf91bd020",
|
||||
"prefix": "curff",
|
||||
"description": "Fast-forward read-only cursor",
|
||||
"body": "/* declare variables */\r\nDECLARE @variable INT\r\n\r\nDECLARE $cursor_name$ CURSOR FAST_FORWARD READ_ONLY FOR $select_statement$\r\n\r\nOPEN $cursor_name$\r\n\r\nFETCH NEXT FROM $cursor_name$ INTO @variable\r\n\r\nWHILE @@FETCH_STATUS = 0\r\nBEGIN\r\n $CURSOR$\r\n\r\n FETCH NEXT FROM $cursor_name$ INTO @variable\r\nEND\r\n\r\nCLOSE $cursor_name$\r\nDEALLOCATE $cursor_name$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cursor_name",
|
||||
"defaultValue": ""
|
||||
},
|
||||
{
|
||||
"name": "select_statement",
|
||||
"defaultValue": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"id": "8e435744-ec4a-4123-af8c-cb1f2203733b",
|
||||
"prefix": "cv_central",
|
||||
"description": "",
|
||||
"body": "USE [Arizona]\r\nDECLARE @subsidiary_id INT \r\nDECLARE @out_default_value VARCHAR(MAX)\r\n\r\nSELECT [d].[BAPD_subsidiary], [d].[BAPD_value]\r\nFROM [dbo].[Bmc_application_key] k\r\n JOIN [dbo].[Bmc_application_default] d ON d.[BAPD_bmc_application_key] = k.[Bmc_application_key_ID]\r\nWHERE CAST(k.[BAPK_key] AS VARCHAR(MAX))= '$cv$'",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cv",
|
||||
"defaultValue": "cvPrimaryCareList"
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "8e435744-ec4a-4123-af8c-cb1f2203733b",
|
||||
"prefix": "cv_central",
|
||||
"description": "",
|
||||
"body": "USE [Arizona]\r\nDECLARE @subsidiary_id INT \r\nDECLARE @out_default_value VARCHAR(MAX)\r\n\r\nSELECT [d].[BAPD_subsidiary], [d].[BAPD_value]\r\nFROM [dbo].[Bmc_application_key] k\r\n JOIN [dbo].[Bmc_application_default] d ON d.[BAPD_bmc_application_key] = k.[Bmc_application_key_ID]\r\nWHERE CAST(k.[BAPK_key] AS VARCHAR(MAX))= '$cv$'",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cv",
|
||||
"defaultValue": "cvPrimaryCareList"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"id": "ecdf5c2f-962f-493a-b0fd-364a90b972e6",
|
||||
"prefix": "cv_phcy",
|
||||
"description": "",
|
||||
"body": "USE [Arizona]\r\nDECLARE @subsidiary_id INT \r\nDECLARE @out_default_value VARCHAR(MAX)\r\n\r\n/* Get Subsidiary */\r\nselect @subsidiary_id = ou.ou_subsidiary\r\n from arizona.dbo.Bmc_application_key bapk (nolock)\r\n join Arizona.dbo.Bmc_application_default bapd (nolock)\r\n on bapd.bapd_bmc_application_key = bapk.bmc_application_key_id\r\n join arizona.dbo.organizational_unit ou (nolock)\r\n on ou.organizational_unit_id = bapd.bapd_value\r\n join arizona.dbo.address ad (nolock)\r\n on ad.address_id = ou.ou_address\r\n where bapk.bapk_key = 'cvCurrentOrganizationalUnit';\r\n\r\n/* Get Common Vars */\r\n\r\nexec dbo.sp_bmc_Bmc_Applic_Default @in_job_type = 3,\r\n @in_param_int_1 = null,\r\n @in_param_int_2 = @subsidiary_id,\r\n @in_param_varchar_1 = '$cv$',\r\n @out_default_value = @out_default_value output,\r\n @out_param_int_1 = null;\r\n\r\nselect @out_default_value AS cvPrimaryCareList, @subsidiary_id AS subsidiary_id\r\n\r\n\r\n\r\n",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cv",
|
||||
"defaultValue": "cvPrimaryCareList"
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "ecdf5c2f-962f-493a-b0fd-364a90b972e6",
|
||||
"prefix": "cv_phcy",
|
||||
"description": "",
|
||||
"body": "USE [Arizona]\r\nDECLARE @subsidiary_id INT \r\nDECLARE @out_default_value VARCHAR(MAX)\r\n\r\n/* Get Subsidiary */\r\nselect @subsidiary_id = ou.ou_subsidiary\r\n from arizona.dbo.Bmc_application_key bapk (nolock)\r\n join Arizona.dbo.Bmc_application_default bapd (nolock)\r\n on bapd.bapd_bmc_application_key = bapk.bmc_application_key_id\r\n join arizona.dbo.organizational_unit ou (nolock)\r\n on ou.organizational_unit_id = bapd.bapd_value\r\n join arizona.dbo.address ad (nolock)\r\n on ad.address_id = ou.ou_address\r\n where bapk.bapk_key = 'cvCurrentOrganizationalUnit';\r\n\r\n/* Get Common Vars */\r\n\r\nexec dbo.sp_bmc_Bmc_Applic_Default @in_job_type = 3,\r\n @in_param_int_1 = null,\r\n @in_param_int_2 = @subsidiary_id,\r\n @in_param_varchar_1 = '$cv$',\r\n @out_default_value = @out_default_value output,\r\n @out_param_int_1 = null;\r\n\r\nselect @out_default_value AS cvPrimaryCareList, @subsidiary_id AS subsidiary_id\r\n\r\n\r\n\r\n",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "cv",
|
||||
"defaultValue": "cvPrimaryCareList"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "23b38bb9-b1ef-4575-9094-2c5f382bdc8d",
|
||||
"prefix": "delTmp",
|
||||
"description": "delete temp table",
|
||||
"body": "IF OBJECT_ID('tempdb..$PASTE$')IS NOT NULL BEGIN;\r\n DROP TABLE $PASTE$;\r\nEND;\r\n"
|
||||
{
|
||||
"id": "23b38bb9-b1ef-4575-9094-2c5f382bdc8d",
|
||||
"prefix": "delTmp",
|
||||
"description": "delete temp table",
|
||||
"body": "IF OBJECT_ID('tempdb..$PASTE$')IS NOT NULL BEGIN;\r\n DROP TABLE $PASTE$;\r\nEND;\r\n"
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"id": "fc0aed2f-0b61-41b6-8491-c49647582f43",
|
||||
"prefix": "df",
|
||||
"description": "DELETE FROM fragment",
|
||||
"body": "DELETE FROM $table_name$ WHERE $CURSOR$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "table_name",
|
||||
"defaultValue": "[schema].[table_name]"
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "fc0aed2f-0b61-41b6-8491-c49647582f43",
|
||||
"prefix": "df",
|
||||
"description": "DELETE FROM fragment",
|
||||
"body": "DELETE FROM $table_name$ WHERE $CURSOR$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "table_name",
|
||||
"defaultValue": "[schema].[table_name]"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "67e4d51f-49ee-4e47-9cac-0bd7496371f3",
|
||||
"prefix": "disable_all_jobs",
|
||||
"description": "generate sql to disable all jobs on the local server",
|
||||
"body": "SELECT 'Exec MSDB.dbo.sp_update_job @job_name = N''' + SJ.name + ''', @Enabled = 0'\r\n FROM msdb..sysjobs SJ\r\n INNER JOIN msdb..syscategories SC\r\n ON SJ.category_id = SC.category_id\r\n WHERE [SJ].[enabled] = 1;"
|
||||
{
|
||||
"id": "67e4d51f-49ee-4e47-9cac-0bd7496371f3",
|
||||
"prefix": "disable_all_jobs",
|
||||
"description": "generate sql to disable all jobs on the local server",
|
||||
"body": "SELECT 'Exec MSDB.dbo.sp_update_job @job_name = N''' + SJ.name + ''', @Enabled = 0'\r\n FROM msdb..sysjobs SJ\r\n INNER JOIN msdb..syscategories SC\r\n ON SJ.category_id = SC.category_id\r\n WHERE [SJ].[enabled] = 1;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "b73c1b25-8626-469e-98a4-5a2ac1eabb64",
|
||||
"prefix": "dmvBadIdx",
|
||||
"description": "check for bad indexes",
|
||||
"body": "-- Possible Bad NC Indexes (writes > reads) (Query 52) (Bad NC Indexes)\r\nSELECT\tOBJECT_NAME(s.[object_id]) AS [Table Name]\r\n\t ,i.name AS [Index Name]\r\n\t ,i.index_id\r\n\t ,i.is_disabled\r\n\t ,i.is_hypothetical\r\n\t ,i.has_filter\r\n\t ,i.fill_factor\r\n\t ,user_updates AS [Total Writes]\r\n\t ,user_seeks + user_scans + user_lookups AS [Total Reads]\r\n\t ,user_updates - (user_seeks + user_scans + user_lookups) AS [Difference]\r\nFROM\tsys.dm_db_index_usage_stats AS s WITH (NOLOCK)\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON s.[object_id] = i.[object_id] AND i.index_id = s.index_id\r\nWHERE\tOBJECTPROPERTY(s.[object_id], 'IsUserTable') = 1\r\n\t\tAND s.database_id = DB_ID()\r\n\t\tAND user_updates > (user_seeks + user_scans + user_lookups)\r\n\t\tAND i.index_id > 1\r\n\t\tAND (user_seeks + user_scans + user_lookups) = 0\r\nORDER BY [Difference] DESC\r\n\t ,[Total Writes] DESC\r\n\t ,[Total Reads] ASC\r\nOPTION\t(RECOMPILE)\r\n;\r\n\r\n-- Look for indexes with high numbers of writes and zero or very low numbers of reads\r\n-- Consider your complete workload, and how long your instance has been running\r\n-- Investigate further before dropping an index!\r\n"
|
||||
{
|
||||
"id": "b73c1b25-8626-469e-98a4-5a2ac1eabb64",
|
||||
"prefix": "dmvBadIdx",
|
||||
"description": "check for bad indexes",
|
||||
"body": "-- Possible Bad NC Indexes (writes > reads) (Query 52) (Bad NC Indexes)\r\nSELECT\tOBJECT_NAME(s.[object_id]) AS [Table Name]\r\n\t ,i.name AS [Index Name]\r\n\t ,i.index_id\r\n\t ,i.is_disabled\r\n\t ,i.is_hypothetical\r\n\t ,i.has_filter\r\n\t ,i.fill_factor\r\n\t ,user_updates AS [Total Writes]\r\n\t ,user_seeks + user_scans + user_lookups AS [Total Reads]\r\n\t ,user_updates - (user_seeks + user_scans + user_lookups) AS [Difference]\r\nFROM\tsys.dm_db_index_usage_stats AS s WITH (NOLOCK)\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON s.[object_id] = i.[object_id] AND i.index_id = s.index_id\r\nWHERE\tOBJECTPROPERTY(s.[object_id], 'IsUserTable') = 1\r\n\t\tAND s.database_id = DB_ID()\r\n\t\tAND user_updates > (user_seeks + user_scans + user_lookups)\r\n\t\tAND i.index_id > 1\r\n\t\tAND (user_seeks + user_scans + user_lookups) = 0\r\nORDER BY [Difference] DESC\r\n\t ,[Total Writes] DESC\r\n\t ,[Total Reads] ASC\r\nOPTION\t(RECOMPILE)\r\n;\r\n\r\n-- Look for indexes with high numbers of writes and zero or very low numbers of reads\r\n-- Consider your complete workload, and how long your instance has been running\r\n-- Investigate further before dropping an index!\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "7df25f65-0eb1-414f-96d5-a150e26c6295",
|
||||
"prefix": "dmvLatency",
|
||||
"description": "check disks latency. cumulative numbers since start of the server",
|
||||
"body": "-- Drive level latency information (Query 19) (Drive Level Latency)\r\n-- Based on code from Jimmy May\r\nSELECT\t[Drive]\r\n\t ,CASE WHEN num_of_reads = 0 THEN 0\r\n\t\t\t ELSE (io_stall_read_ms / num_of_reads)\r\n\t\tEND AS [Read Latency]\r\n\t ,CASE WHEN io_stall_write_ms = 0 THEN 0\r\n\t\t\t ELSE (io_stall_write_ms / num_of_writes)\r\n\t\tEND AS [Write Latency]\r\n\t ,CASE WHEN (num_of_reads = 0 AND num_of_writes = 0 ) THEN 0\r\n\t\t\t ELSE (io_stall / (num_of_reads + num_of_writes))\r\n\t\tEND AS [Overall Latency]\r\n\t ,CASE WHEN num_of_reads = 0 THEN 0\r\n\t\t\t ELSE (num_of_bytes_read / num_of_reads)\r\n\t\tEND AS [Avg Bytes/Read]\r\n\t ,CASE WHEN io_stall_write_ms = 0 THEN 0\r\n\t\t\t ELSE (num_of_bytes_written / num_of_writes)\r\n\t\tEND AS [Avg Bytes/Write]\r\n\t ,CASE WHEN (num_of_reads = 0 AND num_of_writes = 0 ) THEN 0\r\n\t\t\t ELSE ((num_of_bytes_read + num_of_bytes_written) / (num_of_reads + num_of_writes))\r\n\t\tEND AS [Avg Bytes/Transfer]\r\nFROM\t(SELECT\tLEFT(UPPER(mf.physical_name), 2) AS Drive\r\n\t\t\t ,SUM(num_of_reads) AS num_of_reads\r\n\t\t\t ,SUM(io_stall_read_ms) AS io_stall_read_ms\r\n\t\t\t ,SUM(num_of_writes) AS num_of_writes\r\n\t\t\t ,SUM(io_stall_write_ms) AS io_stall_write_ms\r\n\t\t\t ,SUM(num_of_bytes_read) AS num_of_bytes_read\r\n\t\t\t ,SUM(num_of_bytes_written) AS num_of_bytes_written\r\n\t\t\t ,SUM(io_stall) AS io_stall\r\n\t\t FROM\tsys.dm_io_virtual_file_stats(NULL, NULL) AS vfs\r\n\t\t\t\tINNER JOIN sys.master_files AS mf WITH (NOLOCK) ON vfs.database_id = mf.database_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND vfs.file_id = mf.file_id\r\n\t\t GROUP BY LEFT(UPPER(mf.physical_name), 2)\r\n\t\t) AS tab\r\nORDER BY [Overall Latency]\r\nOPTION\t(RECOMPILE);\r\n\r\n-- Shows you the drive-level latency for reads and writes, in milliseconds\r\n"
|
||||
{
|
||||
"id": "7df25f65-0eb1-414f-96d5-a150e26c6295",
|
||||
"prefix": "dmvLatency",
|
||||
"description": "check disks latency. cumulative numbers since start of the server",
|
||||
"body": "-- Drive level latency information (Query 19) (Drive Level Latency)\r\n-- Based on code from Jimmy May\r\nSELECT\t[Drive]\r\n\t ,CASE WHEN num_of_reads = 0 THEN 0\r\n\t\t\t ELSE (io_stall_read_ms / num_of_reads)\r\n\t\tEND AS [Read Latency]\r\n\t ,CASE WHEN io_stall_write_ms = 0 THEN 0\r\n\t\t\t ELSE (io_stall_write_ms / num_of_writes)\r\n\t\tEND AS [Write Latency]\r\n\t ,CASE WHEN (num_of_reads = 0 AND num_of_writes = 0 ) THEN 0\r\n\t\t\t ELSE (io_stall / (num_of_reads + num_of_writes))\r\n\t\tEND AS [Overall Latency]\r\n\t ,CASE WHEN num_of_reads = 0 THEN 0\r\n\t\t\t ELSE (num_of_bytes_read / num_of_reads)\r\n\t\tEND AS [Avg Bytes/Read]\r\n\t ,CASE WHEN io_stall_write_ms = 0 THEN 0\r\n\t\t\t ELSE (num_of_bytes_written / num_of_writes)\r\n\t\tEND AS [Avg Bytes/Write]\r\n\t ,CASE WHEN (num_of_reads = 0 AND num_of_writes = 0 ) THEN 0\r\n\t\t\t ELSE ((num_of_bytes_read + num_of_bytes_written) / (num_of_reads + num_of_writes))\r\n\t\tEND AS [Avg Bytes/Transfer]\r\nFROM\t(SELECT\tLEFT(UPPER(mf.physical_name), 2) AS Drive\r\n\t\t\t ,SUM(num_of_reads) AS num_of_reads\r\n\t\t\t ,SUM(io_stall_read_ms) AS io_stall_read_ms\r\n\t\t\t ,SUM(num_of_writes) AS num_of_writes\r\n\t\t\t ,SUM(io_stall_write_ms) AS io_stall_write_ms\r\n\t\t\t ,SUM(num_of_bytes_read) AS num_of_bytes_read\r\n\t\t\t ,SUM(num_of_bytes_written) AS num_of_bytes_written\r\n\t\t\t ,SUM(io_stall) AS io_stall\r\n\t\t FROM\tsys.dm_io_virtual_file_stats(NULL, NULL) AS vfs\r\n\t\t\t\tINNER JOIN sys.master_files AS mf WITH (NOLOCK) ON vfs.database_id = mf.database_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t AND vfs.file_id = mf.file_id\r\n\t\t GROUP BY LEFT(UPPER(mf.physical_name), 2)\r\n\t\t) AS tab\r\nORDER BY [Overall Latency]\r\nOPTION\t(RECOMPILE);\r\n\r\n-- Shows you the drive-level latency for reads and writes, in milliseconds\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "19e1becb-0cc5-43c4-acc1-0854d9f98596",
|
||||
"prefix": "dmvMissingIdx",
|
||||
"description": "list possible missing indexes",
|
||||
"body": "-- Missing Indexes for all databases by Index Advantage (Query 22) (Missing Indexes All Databases)\r\nSELECT\tCONVERT(DECIMAL(18, 2), user_seeks * avg_total_user_cost * (avg_user_impact * 0.01)) AS [index_advantage]\r\n\t ,migs.last_user_seek\r\n\t ,mid.[statement] AS [Database.Schema.Table]\r\n\t ,mid.equality_columns\r\n\t ,mid.inequality_columns\r\n\t ,mid.included_columns\r\n\t ,migs.unique_compiles\r\n\t ,migs.user_seeks\r\n\t ,migs.avg_total_user_cost\r\n\t ,migs.avg_user_impact\r\nFROM\tsys.dm_db_missing_index_group_stats AS migs WITH (NOLOCK)\r\n\t\tINNER JOIN sys.dm_db_missing_index_groups AS mig WITH (NOLOCK) ON migs.group_handle = mig.index_group_handle\r\n\t\tINNER JOIN sys.dm_db_missing_index_details AS mid WITH (NOLOCK) ON mig.index_handle = mid.index_handle\r\nORDER BY index_advantage DESC\r\nOPTION\t(RECOMPILE);\r\n\r\n-- Getting missing index information for all of the databases on the instance is very useful\r\n-- Look at last user seek time, number of user seeks to help determine source and importance\r\n-- Also look at avg_user_impact and avg_total_user_cost to help determine importance\r\n-- SQL Server is overly eager to add included columns, so beware\r\n-- Do not just blindly add indexes that show up from this query!!!\r\n"
|
||||
{
|
||||
"id": "19e1becb-0cc5-43c4-acc1-0854d9f98596",
|
||||
"prefix": "dmvMissingIdx",
|
||||
"description": "list possible missing indexes",
|
||||
"body": "-- Missing Indexes for all databases by Index Advantage (Query 22) (Missing Indexes All Databases)\r\nSELECT\tCONVERT(DECIMAL(18, 2), user_seeks * avg_total_user_cost * (avg_user_impact * 0.01)) AS [index_advantage]\r\n\t ,migs.last_user_seek\r\n\t ,mid.[statement] AS [Database.Schema.Table]\r\n\t ,mid.equality_columns\r\n\t ,mid.inequality_columns\r\n\t ,mid.included_columns\r\n\t ,migs.unique_compiles\r\n\t ,migs.user_seeks\r\n\t ,migs.avg_total_user_cost\r\n\t ,migs.avg_user_impact\r\nFROM\tsys.dm_db_missing_index_group_stats AS migs WITH (NOLOCK)\r\n\t\tINNER JOIN sys.dm_db_missing_index_groups AS mig WITH (NOLOCK) ON migs.group_handle = mig.index_group_handle\r\n\t\tINNER JOIN sys.dm_db_missing_index_details AS mid WITH (NOLOCK) ON mig.index_handle = mid.index_handle\r\nORDER BY index_advantage DESC\r\nOPTION\t(RECOMPILE);\r\n\r\n-- Getting missing index information for all of the databases on the instance is very useful\r\n-- Look at last user seek time, number of user seeks to help determine source and importance\r\n-- Also look at avg_user_impact and avg_total_user_cost to help determine importance\r\n-- SQL Server is overly eager to add included columns, so beware\r\n-- Do not just blindly add indexes that show up from this query!!!\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "c5965ee1-0c12-4cea-a7a7-ae9638190683",
|
||||
"prefix": "dmvReadWriteIdx",
|
||||
"description": "index read vs write stats",
|
||||
"body": "--- Index Read/Write stats (all tables in current DB) ordered by Reads (Query 62) (Overall Index Usage - Reads)\r\nSELECT\ttblName = o.name\r\n\t\t,o.type\r\n\t ,i.name AS [IndexName]\r\n\t ,i.index_id\r\n\t ,user_seeks + user_scans + user_lookups AS [Reads]\r\n\t ,s.user_updates AS [Writes]\r\n\t ,i.type_desc AS [IndexType]\r\n\t ,i.fill_factor AS [FillFactor]\r\n\t ,i.has_filter\r\n\t ,i.filter_definition\r\n\t ,s.last_user_scan\r\n\t ,s.last_user_lookup\r\n\t ,s.last_user_seek\r\nFROM\tsys.dm_db_index_usage_stats AS s WITH (NOLOCK)\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON s.object_id = i.object_id\r\n\t\tINNER JOIN sys.objects o WITH (NOLOCK) ON s.object_id = o.object_id\r\nWHERE\to.type = 'U' -- user table\r\n\tAND i.index_id = s.index_id\r\n\tAND s.database_id = DB_ID()\r\n\t--AND o.name = 'tblRezeptZeile'\r\n\t--AND i.name = 'idxTblRezeptZeileUniProfilFK'\r\nORDER BY user_seeks + user_scans + user_lookups DESC -- Order by reads\r\n--ORDER BY s.user_updates DESC OPTION \t\t\t\t -- Order by writes\r\nOPTION\t(RECOMPILE);\r\n"
|
||||
{
|
||||
"id": "c5965ee1-0c12-4cea-a7a7-ae9638190683",
|
||||
"prefix": "dmvReadWriteIdx",
|
||||
"description": "index read vs write stats",
|
||||
"body": "--- Index Read/Write stats (all tables in current DB) ordered by Reads (Query 62) (Overall Index Usage - Reads)\r\nSELECT\ttblName = o.name\r\n\t\t,o.type\r\n\t ,i.name AS [IndexName]\r\n\t ,i.index_id\r\n\t ,user_seeks + user_scans + user_lookups AS [Reads]\r\n\t ,s.user_updates AS [Writes]\r\n\t ,i.type_desc AS [IndexType]\r\n\t ,i.fill_factor AS [FillFactor]\r\n\t ,i.has_filter\r\n\t ,i.filter_definition\r\n\t ,s.last_user_scan\r\n\t ,s.last_user_lookup\r\n\t ,s.last_user_seek\r\nFROM\tsys.dm_db_index_usage_stats AS s WITH (NOLOCK)\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON s.object_id = i.object_id\r\n\t\tINNER JOIN sys.objects o WITH (NOLOCK) ON s.object_id = o.object_id\r\nWHERE\to.type = 'U' -- user table\r\n\tAND i.index_id = s.index_id\r\n\tAND s.database_id = DB_ID()\r\n\t--AND o.name = 'tblRezeptZeile'\r\n\t--AND i.name = 'idxTblRezeptZeileUniProfilFK'\r\nORDER BY user_seeks + user_scans + user_lookups DESC -- Order by reads\r\n--ORDER BY s.user_updates DESC OPTION \t\t\t\t -- Order by writes\r\nOPTION\t(RECOMPILE);\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "a4d55aef-b09a-41fc-8dfb-4cb38902d29a",
|
||||
"prefix": "dmvTopQueries",
|
||||
"description": "Top Cached SPs By Avg Elapsed Time ",
|
||||
"body": "SELECT x.[SP Name]\r\n\t ,avg_elapsed_time = SUM(x.total_elapsed_time) / SUM(x.execution_count)\r\n\t ,total_elapsed_time = SUM(x.total_elapsed_time)\r\n\t ,execution_count = SUM(x.execution_count)\r\nFROM(\t\r\n\t\t-- Top Cached SPs By Avg Elapsed Time (SQL 2008 R2) (Query 45) (SP Avg Elapsed Time) \r\n\t\tSELECT TOP(50) p.name AS [SP Name], qs.total_elapsed_time/qs.execution_count AS [avg_elapsed_time], \r\n\t\tqs.total_elapsed_time, qs.execution_count, ISNULL(qs.execution_count/DATEDIFF(Minute, qs.cached_time, \r\n\t\tGETDATE()), 0) AS [Calls/Minute], qs.total_worker_time/qs.execution_count AS [AvgWorkerTime], \r\n\t\tqs.total_worker_time AS [TotalWorkerTime], qs.cached_time\r\n\t\tFROM sys.procedures AS p WITH (NOLOCK)\r\n\t\tINNER JOIN sys.dm_exec_procedure_stats AS qs WITH (NOLOCK)\r\n\t\tON p.[object_id] = qs.[object_id]\r\n\t\tWHERE qs.database_id = DB_ID()\r\n\t\tORDER BY avg_elapsed_time DESC \r\n\t) x \r\nGROUP BY x.[SP Name]\r\nORDER BY SUM(x.total_elapsed_time) DESC OPTION (RECOMPILE)\r\n\r\n-- This helps you find long-running cached stored procedures that\r\n-- may be easy to optimize with standard query tuning techniques\r\n"
|
||||
{
|
||||
"id": "a4d55aef-b09a-41fc-8dfb-4cb38902d29a",
|
||||
"prefix": "dmvTopQueries",
|
||||
"description": "Top Cached SPs By Avg Elapsed Time ",
|
||||
"body": "SELECT x.[SP Name]\r\n\t ,avg_elapsed_time = SUM(x.total_elapsed_time) / SUM(x.execution_count)\r\n\t ,total_elapsed_time = SUM(x.total_elapsed_time)\r\n\t ,execution_count = SUM(x.execution_count)\r\nFROM(\t\r\n\t\t-- Top Cached SPs By Avg Elapsed Time (SQL 2008 R2) (Query 45) (SP Avg Elapsed Time) \r\n\t\tSELECT TOP(50) p.name AS [SP Name], qs.total_elapsed_time/qs.execution_count AS [avg_elapsed_time], \r\n\t\tqs.total_elapsed_time, qs.execution_count, ISNULL(qs.execution_count/DATEDIFF(Minute, qs.cached_time, \r\n\t\tGETDATE()), 0) AS [Calls/Minute], qs.total_worker_time/qs.execution_count AS [AvgWorkerTime], \r\n\t\tqs.total_worker_time AS [TotalWorkerTime], qs.cached_time\r\n\t\tFROM sys.procedures AS p WITH (NOLOCK)\r\n\t\tINNER JOIN sys.dm_exec_procedure_stats AS qs WITH (NOLOCK)\r\n\t\tON p.[object_id] = qs.[object_id]\r\n\t\tWHERE qs.database_id = DB_ID()\r\n\t\tORDER BY avg_elapsed_time DESC \r\n\t) x \r\nGROUP BY x.[SP Name]\r\nORDER BY SUM(x.total_elapsed_time) DESC OPTION (RECOMPILE)\r\n\r\n-- This helps you find long-running cached stored procedures that\r\n-- may be easy to optimize with standard query tuning techniques\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "cdc9ce01-725c-4483-9d8e-b8f0d878066e",
|
||||
"prefix": "dmvTopWaits",
|
||||
"description": "Isolate top waits for server instance since last restart or wait statistics clear",
|
||||
"body": "WITH [Waits] \r\nAS (SELECT wait_type, wait_time_ms/ 1000.0 AS [WaitS],\r\n (wait_time_ms - signal_wait_time_ms) / 1000.0 AS [ResourceS],\r\n signal_wait_time_ms / 1000.0 AS [SignalS],\r\n waiting_tasks_count AS [WaitCount],\r\n 100.0 * wait_time_ms / SUM (wait_time_ms) OVER() AS [Percentage],\r\n ROW_NUMBER() OVER(ORDER BY wait_time_ms DESC) AS [RowNum]\r\n FROM sys.dm_os_wait_stats WITH (NOLOCK)\r\n WHERE [wait_type] NOT IN (\r\n N'BROKER_EVENTHANDLER', N'BROKER_RECEIVE_WAITFOR', N'BROKER_TASK_STOP',\r\n\t\tN'BROKER_TO_FLUSH', N'BROKER_TRANSMITTER', N'CHECKPOINT_QUEUE',\r\n N'CHKPT', N'CLR_AUTO_EVENT', N'CLR_MANUAL_EVENT', N'CLR_SEMAPHORE',\r\n N'DBMIRROR_DBM_EVENT', N'DBMIRROR_EVENTS_QUEUE', N'DBMIRROR_WORKER_QUEUE',\r\n\t\tN'DBMIRRORING_CMD', N'DIRTY_PAGE_POLL', N'DISPATCHER_QUEUE_SEMAPHORE',\r\n N'EXECSYNC', N'FSAGENT', N'FT_IFTS_SCHEDULER_IDLE_WAIT', N'FT_IFTSHC_MUTEX',\r\n N'HADR_CLUSAPI_CALL', N'HADR_FILESTREAM_IOMGR_IOCOMPLETION', N'HADR_LOGCAPTURE_WAIT', \r\n\t\tN'HADR_NOTIFICATION_DEQUEUE', N'HADR_TIMER_TASK', N'HADR_WORK_QUEUE',\r\n N'KSOURCE_WAKEUP', N'LAZYWRITER_SLEEP', N'LOGMGR_QUEUE', N'ONDEMAND_TASK_QUEUE',\r\n N'PWAIT_ALL_COMPONENTS_INITIALIZED', N'QDS_PERSIST_TASK_MAIN_LOOP_SLEEP',\r\n N'QDS_CLEANUP_STALE_QUERIES_TASK_MAIN_LOOP_SLEEP', N'REQUEST_FOR_DEADLOCK_SEARCH',\r\n\t\tN'RESOURCE_QUEUE', N'SERVER_IDLE_CHECK', N'SLEEP_BPOOL_FLUSH', N'SLEEP_DBSTARTUP',\r\n\t\tN'SLEEP_DCOMSTARTUP', N'SLEEP_MASTERDBREADY', N'SLEEP_MASTERMDREADY',\r\n N'SLEEP_MASTERUPGRADED', N'SLEEP_MSDBSTARTUP', N'SLEEP_SYSTEMTASK', N'SLEEP_TASK',\r\n N'SLEEP_TEMPDBSTARTUP', N'SNI_HTTP_ACCEPT', N'SP_SERVER_DIAGNOSTICS_SLEEP',\r\n\t\tN'SQLTRACE_BUFFER_FLUSH', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP', N'SQLTRACE_WAIT_ENTRIES',\r\n\t\tN'WAIT_FOR_RESULTS', N'WAITFOR', N'WAITFOR_TASKSHUTDOWN', N'WAIT_XTP_HOST_WAIT',\r\n\t\tN'WAIT_XTP_OFFLINE_CKPT_NEW_LOG', N'WAIT_XTP_CKPT_CLOSE', N'XE_DISPATCHER_JOIN',\r\n N'XE_DISPATCHER_WAIT', N'XE_TIMER_EVENT')\r\n AND waiting_tasks_count > 0)\r\nSELECT\r\n MAX (W1.wait_type) AS [WaitType],\r\n CAST (MAX (W1.WaitS) AS DECIMAL (16,2)) AS [Wait_Sec],\r\n CAST (MAX (W1.ResourceS) AS DECIMAL (16,2)) AS [Resource_Sec],\r\n CAST (MAX (W1.SignalS) AS DECIMAL (16,2)) AS [Signal_Sec],\r\n MAX (W1.WaitCount) AS [Wait Count],\r\n CAST (MAX (W1.Percentage) AS DECIMAL (5,2)) AS [Wait Percentage],\r\n CAST ((MAX (W1.WaitS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgWait_Sec],\r\n CAST ((MAX (W1.ResourceS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgRes_Sec],\r\n CAST ((MAX (W1.SignalS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgSig_Sec]\r\nFROM Waits AS W1\r\nINNER JOIN Waits AS W2\r\nON W2.RowNum <= W1.RowNum\r\nGROUP BY W1.RowNum\r\nHAVING SUM (W2.Percentage) - MAX (W1.Percentage) < 99 -- percentage threshold\r\nOPTION (RECOMPILE);\r\n\r\n-- The SQL Server Wait Type Repository\r\n-- http://blogs.msdn.com/b/psssql/archive/2009/11/03/the-sql-server-wait-type-repository.aspx\r\n\r\n-- Wait statistics, or please tell me where it hurts\r\n-- http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/\r\n\r\n-- SQL Server 2005 Performance Tuning using the Waits and Queues\r\n-- http://technet.microsoft.com/en-us/library/cc966413.aspx\r\n\r\n-- sys.dm_os_wait_stats (Transact-SQL)\r\n-- http://msdn.microsoft.com/en-us/library/ms179984(v=sql.105).aspx\r\n"
|
||||
{
|
||||
"id": "cdc9ce01-725c-4483-9d8e-b8f0d878066e",
|
||||
"prefix": "dmvTopWaits",
|
||||
"description": "Isolate top waits for server instance since last restart or wait statistics clear",
|
||||
"body": "WITH [Waits] \r\nAS (SELECT wait_type, wait_time_ms/ 1000.0 AS [WaitS],\r\n (wait_time_ms - signal_wait_time_ms) / 1000.0 AS [ResourceS],\r\n signal_wait_time_ms / 1000.0 AS [SignalS],\r\n waiting_tasks_count AS [WaitCount],\r\n 100.0 * wait_time_ms / SUM (wait_time_ms) OVER() AS [Percentage],\r\n ROW_NUMBER() OVER(ORDER BY wait_time_ms DESC) AS [RowNum]\r\n FROM sys.dm_os_wait_stats WITH (NOLOCK)\r\n WHERE [wait_type] NOT IN (\r\n N'BROKER_EVENTHANDLER', N'BROKER_RECEIVE_WAITFOR', N'BROKER_TASK_STOP',\r\n\t\tN'BROKER_TO_FLUSH', N'BROKER_TRANSMITTER', N'CHECKPOINT_QUEUE',\r\n N'CHKPT', N'CLR_AUTO_EVENT', N'CLR_MANUAL_EVENT', N'CLR_SEMAPHORE',\r\n N'DBMIRROR_DBM_EVENT', N'DBMIRROR_EVENTS_QUEUE', N'DBMIRROR_WORKER_QUEUE',\r\n\t\tN'DBMIRRORING_CMD', N'DIRTY_PAGE_POLL', N'DISPATCHER_QUEUE_SEMAPHORE',\r\n N'EXECSYNC', N'FSAGENT', N'FT_IFTS_SCHEDULER_IDLE_WAIT', N'FT_IFTSHC_MUTEX',\r\n N'HADR_CLUSAPI_CALL', N'HADR_FILESTREAM_IOMGR_IOCOMPLETION', N'HADR_LOGCAPTURE_WAIT', \r\n\t\tN'HADR_NOTIFICATION_DEQUEUE', N'HADR_TIMER_TASK', N'HADR_WORK_QUEUE',\r\n N'KSOURCE_WAKEUP', N'LAZYWRITER_SLEEP', N'LOGMGR_QUEUE', N'ONDEMAND_TASK_QUEUE',\r\n N'PWAIT_ALL_COMPONENTS_INITIALIZED', N'QDS_PERSIST_TASK_MAIN_LOOP_SLEEP',\r\n N'QDS_CLEANUP_STALE_QUERIES_TASK_MAIN_LOOP_SLEEP', N'REQUEST_FOR_DEADLOCK_SEARCH',\r\n\t\tN'RESOURCE_QUEUE', N'SERVER_IDLE_CHECK', N'SLEEP_BPOOL_FLUSH', N'SLEEP_DBSTARTUP',\r\n\t\tN'SLEEP_DCOMSTARTUP', N'SLEEP_MASTERDBREADY', N'SLEEP_MASTERMDREADY',\r\n N'SLEEP_MASTERUPGRADED', N'SLEEP_MSDBSTARTUP', N'SLEEP_SYSTEMTASK', N'SLEEP_TASK',\r\n N'SLEEP_TEMPDBSTARTUP', N'SNI_HTTP_ACCEPT', N'SP_SERVER_DIAGNOSTICS_SLEEP',\r\n\t\tN'SQLTRACE_BUFFER_FLUSH', N'SQLTRACE_INCREMENTAL_FLUSH_SLEEP', N'SQLTRACE_WAIT_ENTRIES',\r\n\t\tN'WAIT_FOR_RESULTS', N'WAITFOR', N'WAITFOR_TASKSHUTDOWN', N'WAIT_XTP_HOST_WAIT',\r\n\t\tN'WAIT_XTP_OFFLINE_CKPT_NEW_LOG', N'WAIT_XTP_CKPT_CLOSE', N'XE_DISPATCHER_JOIN',\r\n N'XE_DISPATCHER_WAIT', N'XE_TIMER_EVENT')\r\n AND waiting_tasks_count > 0)\r\nSELECT\r\n MAX (W1.wait_type) AS [WaitType],\r\n CAST (MAX (W1.WaitS) AS DECIMAL (16,2)) AS [Wait_Sec],\r\n CAST (MAX (W1.ResourceS) AS DECIMAL (16,2)) AS [Resource_Sec],\r\n CAST (MAX (W1.SignalS) AS DECIMAL (16,2)) AS [Signal_Sec],\r\n MAX (W1.WaitCount) AS [Wait Count],\r\n CAST (MAX (W1.Percentage) AS DECIMAL (5,2)) AS [Wait Percentage],\r\n CAST ((MAX (W1.WaitS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgWait_Sec],\r\n CAST ((MAX (W1.ResourceS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgRes_Sec],\r\n CAST ((MAX (W1.SignalS) / MAX (W1.WaitCount)) AS DECIMAL (16,4)) AS [AvgSig_Sec]\r\nFROM Waits AS W1\r\nINNER JOIN Waits AS W2\r\nON W2.RowNum <= W1.RowNum\r\nGROUP BY W1.RowNum\r\nHAVING SUM (W2.Percentage) - MAX (W1.Percentage) < 99 -- percentage threshold\r\nOPTION (RECOMPILE);\r\n\r\n-- The SQL Server Wait Type Repository\r\n-- http://blogs.msdn.com/b/psssql/archive/2009/11/03/the-sql-server-wait-type-repository.aspx\r\n\r\n-- Wait statistics, or please tell me where it hurts\r\n-- http://www.sqlskills.com/blogs/paul/wait-statistics-or-please-tell-me-where-it-hurts/\r\n\r\n-- SQL Server 2005 Performance Tuning using the Waits and Queues\r\n-- http://technet.microsoft.com/en-us/library/cc966413.aspx\r\n\r\n-- sys.dm_os_wait_stats (Transact-SQL)\r\n-- http://msdn.microsoft.com/en-us/library/ms179984(v=sql.105).aspx\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "bf168303-81c4-4341-8b76-0a8a152f1404",
|
||||
"prefix": "dmvWaitLocks",
|
||||
"description": "Get lock waits for current database ",
|
||||
"body": "-- Get lock waits for current database (Query 64) (Lock Waits)\r\nSELECT\to.name AS [table_name]\r\n\t ,i.name AS [index_name]\r\n\t ,ios.index_id\r\n\t ,ios.partition_number\r\n\t ,SUM(ios.row_lock_wait_count) AS [total_row_lock_waits]\r\n\t ,SUM(ios.row_lock_wait_in_ms) AS [total_row_lock_wait_in_ms]\r\n\t ,SUM(ios.page_lock_wait_count) AS [total_page_lock_waits]\r\n\t ,SUM(ios.page_lock_wait_in_ms) AS [total_page_lock_wait_in_ms]\r\n\t ,SUM(ios.page_lock_wait_in_ms) + SUM(row_lock_wait_in_ms) AS [total_lock_wait_in_ms]\r\nFROM\tsys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) AS ios\r\n\t\tINNER JOIN sys.objects AS o WITH (NOLOCK) ON ios.[object_id] = o.[object_id]\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON ios.[object_id] = i.[object_id]\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND ios.index_id = i.index_id\r\nWHERE\to.[object_id] > 100\r\nGROUP BY o.name\r\n\t ,i.name\r\n\t ,ios.index_id\r\n\t ,ios.partition_number\r\nHAVING\tSUM(ios.page_lock_wait_in_ms) + SUM(row_lock_wait_in_ms) > 0\r\nORDER BY total_lock_wait_in_ms DESC\r\nOPTION\t(RECOMPILE);\r\n"
|
||||
{
|
||||
"id": "bf168303-81c4-4341-8b76-0a8a152f1404",
|
||||
"prefix": "dmvWaitLocks",
|
||||
"description": "Get lock waits for current database ",
|
||||
"body": "-- Get lock waits for current database (Query 64) (Lock Waits)\r\nSELECT\to.name AS [table_name]\r\n\t ,i.name AS [index_name]\r\n\t ,ios.index_id\r\n\t ,ios.partition_number\r\n\t ,SUM(ios.row_lock_wait_count) AS [total_row_lock_waits]\r\n\t ,SUM(ios.row_lock_wait_in_ms) AS [total_row_lock_wait_in_ms]\r\n\t ,SUM(ios.page_lock_wait_count) AS [total_page_lock_waits]\r\n\t ,SUM(ios.page_lock_wait_in_ms) AS [total_page_lock_wait_in_ms]\r\n\t ,SUM(ios.page_lock_wait_in_ms) + SUM(row_lock_wait_in_ms) AS [total_lock_wait_in_ms]\r\nFROM\tsys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) AS ios\r\n\t\tINNER JOIN sys.objects AS o WITH (NOLOCK) ON ios.[object_id] = o.[object_id]\r\n\t\tINNER JOIN sys.indexes AS i WITH (NOLOCK) ON ios.[object_id] = i.[object_id]\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t AND ios.index_id = i.index_id\r\nWHERE\to.[object_id] > 100\r\nGROUP BY o.name\r\n\t ,i.name\r\n\t ,ios.index_id\r\n\t ,ios.partition_number\r\nHAVING\tSUM(ios.page_lock_wait_in_ms) + SUM(row_lock_wait_in_ms) > 0\r\nORDER BY total_lock_wait_in_ms DESC\r\nOPTION\t(RECOMPILE);\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "6115073f-913a-4afd-adfa-879dd4faf94d",
|
||||
"prefix": "dump",
|
||||
"description": "make a full instance dump",
|
||||
"body": "EXEC [HCITools].dbo.[bkp_Dump] @in_Recovery_Model = 'FULL,SIMPLE';"
|
||||
{
|
||||
"id": "6115073f-913a-4afd-adfa-879dd4faf94d",
|
||||
"prefix": "dump",
|
||||
"description": "make a full instance dump",
|
||||
"body": "EXEC [HCITools].dbo.[bkp_Dump] @in_Recovery_Model = 'FULL,SIMPLE';"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "8a40a419-39e7-47d4-b0d2-823dd63f03d6",
|
||||
"prefix": "eata",
|
||||
"description": "Add column (enhanced edition)",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2018\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/customizing-sql-prompt-built-snippets-better-ata-snippet\r\n**/\r\n\r\nUSE <database, sysname, $DBNAME$>\r\nGO\r\n \r\n-- Add a new column to the table\r\nALTER TABLE <Name of the Schema, sysname, dbo>.<Table name, sysname, $SELECTEDTEXT$>\r\n ADD <Name of the new column, sysname, MyColumn> <datatype of this column,, datetime> <NULL or NOT NULL (allow nulls?),, NULL> -- <What is this column for?, sysname, unknown>\r\nGO\r\nEXEC sys.sp_addextendedproperty \r\n@name = N'MS_Description', \r\n@value = N'<What is this column for?, sysname, unknown>', \r\n@level0type = N'SCHEMA', @level0name = <Name of the Schema, sysname, dbo>, \r\n@level1type = N'TABLE', @level1name = <Table name, sysname, $SELECTEDTEXT$>,\r\n@level2type = N'COLUMN', @level2name = <Name of the new column, sysname, MyColumn>;"
|
||||
{
|
||||
"id": "8a40a419-39e7-47d4-b0d2-823dd63f03d6",
|
||||
"prefix": "eata",
|
||||
"description": "Add column (enhanced edition)",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2018\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/customizing-sql-prompt-built-snippets-better-ata-snippet\r\n**/\r\n\r\nUSE <database, sysname, $DBNAME$>\r\nGO\r\n \r\n-- Add a new column to the table\r\nALTER TABLE <Name of the Schema, sysname, dbo>.<Table name, sysname, $SELECTEDTEXT$>\r\n ADD <Name of the new column, sysname, MyColumn> <datatype of this column,, datetime> <NULL or NOT NULL (allow nulls?),, NULL> -- <What is this column for?, sysname, unknown>\r\nGO\r\nEXEC sys.sp_addextendedproperty \r\n@name = N'MS_Description', \r\n@value = N'<What is this column for?, sysname, unknown>', \r\n@level0type = N'SCHEMA', @level0name = <Name of the Schema, sysname, dbo>, \r\n@level1type = N'TABLE', @level1name = <Table name, sysname, $SELECTEDTEXT$>,\r\n@level2type = N'COLUMN', @level2name = <Name of the new column, sysname, MyColumn>;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "92471cc6-9e3b-446c-995c-8ce2f9905b3f",
|
||||
"prefix": "find_fk",
|
||||
"description": "find fk in a db, per tables, schema, or all",
|
||||
"body": "SELECT\r\n SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.name AS [table]\r\n ,col.column_id\r\n ,col.name AS column_name\r\n ,CASE\r\n WHEN fk.OBJECT_ID IS NOT NULL THEN '>-'\r\n ELSE NULL\r\n END AS rel\r\n ,SCHEMA_NAME(pk_tab.SCHEMA_ID) + '.' + pk_tab.name AS primary_table\r\n ,pk_col.name AS pk_column_name\r\n ,fk_cols.constraint_column_id AS NO\r\n ,fk.name AS fk_constraint_name\r\nFROM sys.tables tab\r\n INNER JOIN sys.columns col\r\n ON col.OBJECT_ID = tab.OBJECT_ID\r\n LEFT OUTER JOIN sys.foreign_key_columns fk_cols\r\n ON fk_cols.parent_object_id = tab.OBJECT_ID\r\n AND fk_cols.parent_column_id = col.column_id\r\n LEFT OUTER JOIN sys.foreign_keys fk\r\n ON fk.OBJECT_ID = fk_cols.constraint_object_id\r\n LEFT OUTER JOIN sys.tables pk_tab\r\n ON pk_tab.OBJECT_ID = fk_cols.referenced_object_id\r\n LEFT OUTER JOIN sys.columns pk_col\r\n ON pk_col.column_id = fk_cols.referenced_column_id\r\n AND pk_col.OBJECT_ID = fk_cols.referenced_object_id\r\nWHERE fk.OBJECT_ID IS NOT NULL\r\nAND SCHEMA_NAME(tab.SCHEMA_ID) = 'dbo'\r\n--AND tab.name='entry'$CURSOR$\r\nORDER BY SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.name\r\n ,col.column_id;"
|
||||
{
|
||||
"id": "92471cc6-9e3b-446c-995c-8ce2f9905b3f",
|
||||
"prefix": "find_fk",
|
||||
"description": "find fk in a db, per tables, schema, or all",
|
||||
"body": "SELECT\r\n SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.name AS [table]\r\n ,col.column_id\r\n ,col.name AS column_name\r\n ,CASE\r\n WHEN fk.OBJECT_ID IS NOT NULL THEN '>-'\r\n ELSE NULL\r\n END AS rel\r\n ,SCHEMA_NAME(pk_tab.SCHEMA_ID) + '.' + pk_tab.name AS primary_table\r\n ,pk_col.name AS pk_column_name\r\n ,fk_cols.constraint_column_id AS NO\r\n ,fk.name AS fk_constraint_name\r\nFROM sys.tables tab\r\n INNER JOIN sys.columns col\r\n ON col.OBJECT_ID = tab.OBJECT_ID\r\n LEFT OUTER JOIN sys.foreign_key_columns fk_cols\r\n ON fk_cols.parent_object_id = tab.OBJECT_ID\r\n AND fk_cols.parent_column_id = col.column_id\r\n LEFT OUTER JOIN sys.foreign_keys fk\r\n ON fk.OBJECT_ID = fk_cols.constraint_object_id\r\n LEFT OUTER JOIN sys.tables pk_tab\r\n ON pk_tab.OBJECT_ID = fk_cols.referenced_object_id\r\n LEFT OUTER JOIN sys.columns pk_col\r\n ON pk_col.column_id = fk_cols.referenced_column_id\r\n AND pk_col.OBJECT_ID = fk_cols.referenced_object_id\r\nWHERE fk.OBJECT_ID IS NOT NULL\r\nAND SCHEMA_NAME(tab.SCHEMA_ID) = 'dbo'\r\n--AND tab.name='entry'$CURSOR$\r\nORDER BY SCHEMA_NAME(tab.SCHEMA_ID) + '.' + tab.name\r\n ,col.column_id;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "e179aa64-7830-440b-a199-9c0a65750a8f",
|
||||
"prefix": "find_query_plan_handle",
|
||||
"description": "find a query plan from the cache and if needed drop it from the cache",
|
||||
"body": "DECLARE @SearchForSql AS NVARCHAR(MAX) = N'TEXT_TO_FIND';\r\n\r\nSELECT usecounts,\r\n cacheobjtype,\r\n objtype,\r\n text,\r\n query_plan,\r\n [plan_handle]\r\n FROM sys.dm_exec_cached_plans\r\n CROSS APPLY sys.dm_exec_sql_text(plan_handle)\r\n CROSS APPLY sys.dm_exec_query_plan(plan_handle)\r\n WHERE text LIKE CONCAT('%', @SearchForSql, '%')\r\n AND text NOT LIKE '%-- Self Reference Marker --%';\r\n\r\n--DBCC FREEPROCCACHE (plan_handle_id_goes_here)"
|
||||
{
|
||||
"id": "e179aa64-7830-440b-a199-9c0a65750a8f",
|
||||
"prefix": "find_query_plan_handle",
|
||||
"description": "find a query plan from the cache and if needed drop it from the cache",
|
||||
"body": "DECLARE @SearchForSql AS NVARCHAR(MAX) = N'TEXT_TO_FIND';\r\n\r\nSELECT usecounts,\r\n cacheobjtype,\r\n objtype,\r\n text,\r\n query_plan,\r\n [plan_handle]\r\n FROM sys.dm_exec_cached_plans\r\n CROSS APPLY sys.dm_exec_sql_text(plan_handle)\r\n CROSS APPLY sys.dm_exec_query_plan(plan_handle)\r\n WHERE text LIKE CONCAT('%', @SearchForSql, '%')\r\n AND text NOT LIKE '%-- Self Reference Marker --%';\r\n\r\n--DBCC FREEPROCCACHE (plan_handle_id_goes_here)"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "1eb7ea47-6ad2-40fd-a2b6-810996566e41",
|
||||
"prefix": "fj",
|
||||
"description": "FULL JOIN fragment",
|
||||
"body": "FULL JOIN "
|
||||
{
|
||||
"id": "1eb7ea47-6ad2-40fd-a2b6-810996566e41",
|
||||
"prefix": "fj",
|
||||
"description": "FULL JOIN fragment",
|
||||
"body": "FULL JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "03c4d511-8dc8-4ca8-9893-a5b7bcaf6181",
|
||||
"prefix": "flh",
|
||||
"description": "print message without waiting for buffer to fill",
|
||||
"body": "RAISERROR ('$CURSOR$', 0, 1) WITH NOWAIT;\r\n"
|
||||
{
|
||||
"id": "03c4d511-8dc8-4ca8-9893-a5b7bcaf6181",
|
||||
"prefix": "flh",
|
||||
"description": "print message without waiting for buffer to fill",
|
||||
"body": "RAISERROR ('$CURSOR$', 0, 1) WITH NOWAIT;\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "b28b4fb4-9f5f-407b-93a0-81134c0d51d7",
|
||||
"prefix": "foj",
|
||||
"description": "FULL OUTER JOIN fragment",
|
||||
"body": "FULL OUTER JOIN "
|
||||
{
|
||||
"id": "b28b4fb4-9f5f-407b-93a0-81134c0d51d7",
|
||||
"prefix": "foj",
|
||||
"description": "FULL OUTER JOIN fragment",
|
||||
"body": "FULL OUTER JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "59cdebdd-b515-4da4-b9f2-b5a552d5d736",
|
||||
"prefix": "free_disk_space",
|
||||
"description": "list disk usage and free space where db files are present",
|
||||
"body": "--free disk space\r\nselect distinct\r\nconvert(varchar(512), b.volume_mount_point) as [volume_mount_point]\r\n, convert(varchar(512), b.logical_volume_name) as [logical_volume_name]\r\n, convert(decimal(18,1), round(((convert(float, b.available_bytes) / convert(float, b.total_bytes)) * 100),1)) as [percent_free]\r\n, convert(bigint, round(((b.available_bytes / 1024.0)/1024.0),0)) as [free_mb]\r\n, convert(bigint, round(((b.total_bytes / 1024.0)/1024.0),0)) as [total_mb]\r\n, convert(bigint, round((((b.total_bytes - b.available_bytes) / 1024.0)/1024.0),0)) as [used_mb]\r\n, CURRENT_TIMESTAMP AS now\r\n,REPLACE(@@SERVERNAME ,'\\apssql','')AS srvName\r\nfrom sys.master_files as [a]\r\nCROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) as [b]\r\nORDER BY [percent_free] ASC \r\n"
|
||||
{
|
||||
"id": "59cdebdd-b515-4da4-b9f2-b5a552d5d736",
|
||||
"prefix": "free_disk_space",
|
||||
"description": "list disk usage and free space where db files are present",
|
||||
"body": "--free disk space\r\nselect distinct\r\nconvert(varchar(512), b.volume_mount_point) as [volume_mount_point]\r\n, convert(varchar(512), b.logical_volume_name) as [logical_volume_name]\r\n, convert(decimal(18,1), round(((convert(float, b.available_bytes) / convert(float, b.total_bytes)) * 100),1)) as [percent_free]\r\n, convert(bigint, round(((b.available_bytes / 1024.0)/1024.0),0)) as [free_mb]\r\n, convert(bigint, round(((b.total_bytes / 1024.0)/1024.0),0)) as [total_mb]\r\n, convert(bigint, round((((b.total_bytes - b.available_bytes) / 1024.0)/1024.0),0)) as [used_mb]\r\n, CURRENT_TIMESTAMP AS now\r\n,REPLACE(@@SERVERNAME ,'\\apssql','')AS srvName\r\nfrom sys.master_files as [a]\r\nCROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) as [b]\r\nORDER BY [percent_free] ASC \r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "08831009-8e82-449e-ba11-53c03289ed6f",
|
||||
"prefix": "gb",
|
||||
"description": "GROUP BY fragment",
|
||||
"body": "GROUP BY "
|
||||
{
|
||||
"id": "08831009-8e82-449e-ba11-53c03289ed6f",
|
||||
"prefix": "gb",
|
||||
"description": "GROUP BY fragment",
|
||||
"body": "GROUP BY "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "fcdb6507-ae0e-4736-85b1-f88b50c64ab0",
|
||||
"prefix": "get_ou",
|
||||
"description": "get the local pharmacy OU into @ou_id",
|
||||
"body": "DECLARE @ou_id INT \r\nEXEC Arizona.dbo.sp_bmc_Bmc_Applic_Default \r\n @in_job_type = 3,\r\n @in_param_int_1 = null, /* Company */\r\n @in_param_int_2 = null, /* Subsidiary */\r\n @in_param_varchar_1 = 'cvCurrentOrganizationalUnit',\r\n @out_default_value = @ou_id output,\r\n @out_param_int_1 = null"
|
||||
{
|
||||
"id": "fcdb6507-ae0e-4736-85b1-f88b50c64ab0",
|
||||
"prefix": "get_ou",
|
||||
"description": "get the local pharmacy OU into @ou_id",
|
||||
"body": "DECLARE @ou_id INT \r\nEXEC Arizona.dbo.sp_bmc_Bmc_Applic_Default \r\n @in_job_type = 3,\r\n @in_param_int_1 = null, /* Company */\r\n @in_param_int_2 = null, /* Subsidiary */\r\n @in_param_varchar_1 = 'cvCurrentOrganizationalUnit',\r\n @out_default_value = @ou_id output,\r\n @out_param_int_1 = null"
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"id": "2936aeed-26d4-416e-8c83-40b190dfca8a",
|
||||
"prefix": "hdr",
|
||||
"description": "simple header",
|
||||
"body": "/*============================================================================= \r\n\r\n$summary$\r\n\r\nParameters\r\n----------------------\r\n\r\n\r\nContext\r\n----------------------\r\n$contexte$\r\n\r\nCreation : $DATE(dd.MM.yyyy)$ / TSC\r\nModifications:\r\n\r\n=============================================================================*/ ",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "summary",
|
||||
"defaultValue": "What does it does ?"
|
||||
},
|
||||
{
|
||||
"name": "contexte",
|
||||
"defaultValue": "What is the context, where does it needs to run ?"
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "2936aeed-26d4-416e-8c83-40b190dfca8a",
|
||||
"prefix": "hdr",
|
||||
"description": "simple header",
|
||||
"body": "/*============================================================================= \r\n\r\n$summary$\r\n\r\nParameters\r\n----------------------\r\n\r\n\r\nContext\r\n----------------------\r\n$contexte$\r\n\r\nCreation : $DATE(dd.MM.yyyy)$ / TSC\r\nModifications:\r\n\r\n=============================================================================*/ ",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "summary",
|
||||
"defaultValue": "What does it does ?"
|
||||
},
|
||||
{
|
||||
"name": "contexte",
|
||||
"defaultValue": "What is the context, where does it needs to run ?"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "4c4fa08a-025e-4fc1-b7a6-0eeec07eda83",
|
||||
"prefix": "heap",
|
||||
"description": "list all heap table(s)",
|
||||
"body": "-- List all heap tables \r\nSELECT SCH.name + '.' + TBL.name AS TableName \r\nFROM sys.tables AS TBL \r\n INNER JOIN sys.schemas AS SCH \r\n ON TBL.schema_id = SCH.schema_id \r\n INNER JOIN sys.indexes AS IDX \r\n ON TBL.object_id = IDX.object_id \r\n AND IDX.type = 0 -- = Heap \r\nORDER BY TableName"
|
||||
{
|
||||
"id": "4c4fa08a-025e-4fc1-b7a6-0eeec07eda83",
|
||||
"prefix": "heap",
|
||||
"description": "list all heap table(s)",
|
||||
"body": "-- List all heap tables \r\nSELECT SCH.name + '.' + TBL.name AS TableName \r\nFROM sys.tables AS TBL \r\n INNER JOIN sys.schemas AS SCH \r\n ON TBL.schema_id = SCH.schema_id \r\n INNER JOIN sys.indexes AS IDX \r\n ON TBL.object_id = IDX.object_id \r\n AND IDX.type = 0 -- = Heap \r\nORDER BY TableName"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "77e7b615-5c82-407e-bea7-71d7c4a29e64",
|
||||
"prefix": "hlog",
|
||||
"description": "new log line in header",
|
||||
"body": "$DATE(dd.MM.yyyy)$ / TSC"
|
||||
{
|
||||
"id": "77e7b615-5c82-407e-bea7-71d7c4a29e64",
|
||||
"prefix": "hlog",
|
||||
"description": "new log line in header",
|
||||
"body": "$DATE(dd.MM.yyyy)$ / TSC"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,16 +1,16 @@
|
||||
{
|
||||
"id": "57ed331c-5e96-43bf-a88d-53b47658a9cc",
|
||||
"prefix": "idxCheck",
|
||||
"description": "IF block with check if an index exists",
|
||||
"body": "IF INDEXPROPERTY(OBJECT_ID('$table$'), '$idxName$' , 'IndexID' ) IS NOT NULL BEGIN;\r\n\t$CURSOR$\r\nEND;\r\n",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "table",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "idxName",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "57ed331c-5e96-43bf-a88d-53b47658a9cc",
|
||||
"prefix": "idxCheck",
|
||||
"description": "IF block with check if an index exists",
|
||||
"body": "IF INDEXPROPERTY(OBJECT_ID('$table$'), '$idxName$' , 'IndexID' ) IS NOT NULL BEGIN;\r\n\t$CURSOR$\r\nEND;\r\n",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "table",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "idxName",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "e73221cc-c9ce-4a44-9d70-0f8d81e0b66f",
|
||||
"prefix": "ij",
|
||||
"description": "INNER JOIN fragment",
|
||||
"body": "JOIN "
|
||||
{
|
||||
"id": "e73221cc-c9ce-4a44-9d70-0f8d81e0b66f",
|
||||
"prefix": "ij",
|
||||
"description": "INNER JOIN fragment",
|
||||
"body": "JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "436caa4d-2f0c-4638-9457-971734c1e8bd",
|
||||
"prefix": "last_bkp",
|
||||
"description": "see last full backups",
|
||||
"body": "WITH LastBackUp AS\r\n(\r\n SELECT bs.database_name,\r\n bs.backup_size,\r\n bs.backup_start_date,\r\n bmf.physical_device_name,\r\n Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )\r\n FROM msdb.dbo.backupmediafamily bmf\r\n JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id\r\n JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id\r\n WHERE bs.[type] = 'D'\r\n AND bs.is_copy_only = 0\r\n)\r\n,lastBkpYesterday AS (\r\n SELECT bs.database_name,\r\n bs.backup_size,\r\n bs.backup_start_date,\r\n bmf.physical_device_name,\r\n Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )\r\n FROM msdb.dbo.backupmediafamily bmf\r\n JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id\r\n JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id\r\n WHERE bs.[type] = 'D'\r\n AND bs.is_copy_only = 0\r\n AND bs.backup_start_date < DATEADD(DAY,0,DATEDIFF(DAY,0,GETDATE()))\r\n)\r\nSELECT \r\n sd.name AS [Database],\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, lb.backup_size / 1048576), 1),',',''''),'.00','') AS [backup size MB],\r\n lb.backup_start_date AS [Last Full DB Backup Date],\r\n lb.physical_device_name AS [Last Backup File Location],\r\n lby.backup_start_date AS [Yesterday Full DB Backup Date],\r\n lb.physical_device_name AS [Yesterday Backup File Location]\r\nFROM sys.databases AS sd\r\n LEFT JOIN LastBackUp AS lb ON sd.name = lb.database_name AND lb.Position = 1\r\n LEFT JOIN lastBkpYesterday lby ON sd.name=lby.database_name and lby.Position=1\r\nORDER BY [Database];\r\n\r\n"
|
||||
{
|
||||
"id": "436caa4d-2f0c-4638-9457-971734c1e8bd",
|
||||
"prefix": "last_bkp",
|
||||
"description": "see last full backups",
|
||||
"body": "WITH LastBackUp AS\r\n(\r\n SELECT bs.database_name,\r\n bs.backup_size,\r\n bs.backup_start_date,\r\n bmf.physical_device_name,\r\n Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )\r\n FROM msdb.dbo.backupmediafamily bmf\r\n JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id\r\n JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id\r\n WHERE bs.[type] = 'D'\r\n AND bs.is_copy_only = 0\r\n)\r\n,lastBkpYesterday AS (\r\n SELECT bs.database_name,\r\n bs.backup_size,\r\n bs.backup_start_date,\r\n bmf.physical_device_name,\r\n Position = ROW_NUMBER() OVER( PARTITION BY bs.database_name ORDER BY bs.backup_start_date DESC )\r\n FROM msdb.dbo.backupmediafamily bmf\r\n JOIN msdb.dbo.backupmediaset bms ON bmf.media_set_id = bms.media_set_id\r\n JOIN msdb.dbo.backupset bs ON bms.media_set_id = bs.media_set_id\r\n WHERE bs.[type] = 'D'\r\n AND bs.is_copy_only = 0\r\n AND bs.backup_start_date < DATEADD(DAY,0,DATEDIFF(DAY,0,GETDATE()))\r\n)\r\nSELECT \r\n sd.name AS [Database],\r\n REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, lb.backup_size / 1048576), 1),',',''''),'.00','') AS [backup size MB],\r\n lb.backup_start_date AS [Last Full DB Backup Date],\r\n lb.physical_device_name AS [Last Backup File Location],\r\n lby.backup_start_date AS [Yesterday Full DB Backup Date],\r\n lb.physical_device_name AS [Yesterday Backup File Location]\r\nFROM sys.databases AS sd\r\n LEFT JOIN LastBackUp AS lb ON sd.name = lb.database_name AND lb.Position = 1\r\n LEFT JOIN lastBkpYesterday lby ON sd.name=lby.database_name and lby.Position=1\r\nORDER BY [Database];\r\n\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "68d2751a-42d4-45e5-8d0a-a3c3f7cb4eee",
|
||||
"prefix": "list_triggers",
|
||||
"description": "list all triggers in the current db",
|
||||
"body": "SELECT table_name = OBJECT_NAME(parent_object_id) ,\r\n trigger_name = name ,\r\n trigger_owner = USER_NAME(schema_id) ,\r\n OBJECTPROPERTY(object_id, 'ExecIsUpdateTrigger') AS isupdate ,\r\n OBJECTPROPERTY(object_id, 'ExecIsDeleteTrigger') AS isdelete ,\r\n OBJECTPROPERTY(object_id, 'ExecIsInsertTrigger') AS isinsert ,\r\n OBJECTPROPERTY(object_id, 'ExecIsAfterTrigger') AS isafter ,\r\n OBJECTPROPERTY(object_id, 'ExecIsInsteadOfTrigger') AS isinsteadof ,\r\n CASE OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled')\r\n WHEN 1 THEN 'Disabled'\r\n ELSE 'Enabled'\r\n END AS status\r\nFROM sys.objects\r\nWHERE type = 'TR'\r\n--$CURSOR$AND [name] LIKE '%vesta%'\r\nORDER BY OBJECT_NAME(parent_object_id)"
|
||||
{
|
||||
"id": "68d2751a-42d4-45e5-8d0a-a3c3f7cb4eee",
|
||||
"prefix": "list_triggers",
|
||||
"description": "list all triggers in the current db",
|
||||
"body": "SELECT table_name = OBJECT_NAME(parent_object_id) ,\r\n trigger_name = name ,\r\n trigger_owner = USER_NAME(schema_id) ,\r\n OBJECTPROPERTY(object_id, 'ExecIsUpdateTrigger') AS isupdate ,\r\n OBJECTPROPERTY(object_id, 'ExecIsDeleteTrigger') AS isdelete ,\r\n OBJECTPROPERTY(object_id, 'ExecIsInsertTrigger') AS isinsert ,\r\n OBJECTPROPERTY(object_id, 'ExecIsAfterTrigger') AS isafter ,\r\n OBJECTPROPERTY(object_id, 'ExecIsInsteadOfTrigger') AS isinsteadof ,\r\n CASE OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled')\r\n WHEN 1 THEN 'Disabled'\r\n ELSE 'Enabled'\r\n END AS status\r\nFROM sys.objects\r\nWHERE type = 'TR'\r\n--$CURSOR$AND [name] LIKE '%vesta%'\r\nORDER BY OBJECT_NAME(parent_object_id)"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "fcc48410-f0a9-43ff-b257-ef36d4ed7923",
|
||||
"prefix": "lj",
|
||||
"description": "LEFT JOIN fragment",
|
||||
"body": "LEFT JOIN "
|
||||
{
|
||||
"id": "fcc48410-f0a9-43ff-b257-ef36d4ed7923",
|
||||
"prefix": "lj",
|
||||
"description": "LEFT JOIN fragment",
|
||||
"body": "LEFT JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "99e2f5cc-5da0-4121-8f2e-082c6c4c1211",
|
||||
"prefix": "loj",
|
||||
"description": "LEFT OUTER JOIN fragment",
|
||||
"body": "LEFT OUTER JOIN "
|
||||
{
|
||||
"id": "99e2f5cc-5da0-4121-8f2e-082c6c4c1211",
|
||||
"prefix": "loj",
|
||||
"description": "LEFT OUTER JOIN fragment",
|
||||
"body": "LEFT OUTER JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "badb18aa-a652-4f7e-a6fc-ae6d2a4c90d5",
|
||||
"prefix": "mio",
|
||||
"description": "only my hostname",
|
||||
"body": "IF HOST_NAME()='CGAL41556'\r\nBEGIN\r\n \r\nEND "
|
||||
{
|
||||
"id": "badb18aa-a652-4f7e-a6fc-ae6d2a4c90d5",
|
||||
"prefix": "mio",
|
||||
"description": "only my hostname",
|
||||
"body": "IF HOST_NAME()='CGAL41556'\r\nBEGIN\r\n \r\nEND "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ffc01a1e-c871-47db-9265-d31ee09e0802",
|
||||
"prefix": "mon",
|
||||
"description": "check des triggers monitoring ",
|
||||
"body": "--should yields around 240 \r\nselect count(*) from Arizona.sys.triggers\r\nwhere name like '%Mon%'"
|
||||
{
|
||||
"id": "ffc01a1e-c871-47db-9265-d31ee09e0802",
|
||||
"prefix": "mon",
|
||||
"description": "check des triggers monitoring ",
|
||||
"body": "--should yields around 240 \r\nselect count(*) from Arizona.sys.triggers\r\nwhere name like '%Mon%'"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "a9eb2b32-353d-4eb3-a1d9-a89a1440a2ba",
|
||||
"prefix": "monitor_amr",
|
||||
"description": "list amr pending in the pharmacy",
|
||||
"body": "EXEC [ActiveSystemServer].[amr].[MonitoringReport]"
|
||||
{
|
||||
"id": "a9eb2b32-353d-4eb3-a1d9-a89a1440a2ba",
|
||||
"prefix": "monitor_amr",
|
||||
"description": "list amr pending in the pharmacy",
|
||||
"body": "EXEC [ActiveSystemServer].[amr].[MonitoringReport]"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "b5ab431f-3892-4b58-ac91-d7befb0ee191",
|
||||
"prefix": "mro",
|
||||
"description": "Retrieve 20 most recently created objects",
|
||||
"body": "\r\n -- NOTE: 'sys.objects'/'create_date' is only available in SQL Server 2005+. Replace with 'sysobjects'/'crdate' in SQL Server 2000.\r\nSELECT TOP (20) [name], [type], create_date\r\nFROM sys.objects\r\nORDER BY create_date DESC"
|
||||
{
|
||||
"id": "b5ab431f-3892-4b58-ac91-d7befb0ee191",
|
||||
"prefix": "mro",
|
||||
"description": "Retrieve 20 most recently created objects",
|
||||
"body": "\r\n -- NOTE: 'sys.objects'/'create_date' is only available in SQL Server 2005+. Replace with 'sysobjects'/'crdate' in SQL Server 2000.\r\nSELECT TOP (20) [name], [type], create_date\r\nFROM sys.objects\r\nORDER BY create_date DESC"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ba5eb4fd-ac8f-427c-a24a-5cb97b8faa98",
|
||||
"prefix": "nbr",
|
||||
"description": "variable table with 10 rows, for cross join population",
|
||||
"body": "DECLARE @nbr TABLE (\r\n\tval INT\r\n);\r\nINSERT INTO @nbr(val)\r\nVALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);\r\n"
|
||||
{
|
||||
"id": "ba5eb4fd-ac8f-427c-a24a-5cb97b8faa98",
|
||||
"prefix": "nbr",
|
||||
"description": "variable table with 10 rows, for cross join population",
|
||||
"body": "DECLARE @nbr TABLE (\r\n\tval INT\r\n);\r\nINSERT INTO @nbr(val)\r\nVALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);\r\n"
|
||||
}
|
||||
@@ -1,24 +1,24 @@
|
||||
{
|
||||
"id": "7d139776-36e1-44e4-98a4-7360ca60dc70",
|
||||
"prefix": "newCol",
|
||||
"description": "add new column",
|
||||
"body": "IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$table$' AND TABLE_SCHEMA='$schema$' AND COLUMN_NAME = '$column$')\r\nBEGIN\r\n\tALTER TABLE $schema$.$table$ ADD $column$ $type$ NOT NULL;\r\nEND ",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "schema",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "table",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "column",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "type",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "7d139776-36e1-44e4-98a4-7360ca60dc70",
|
||||
"prefix": "newCol",
|
||||
"description": "add new column",
|
||||
"body": "IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$table$' AND TABLE_SCHEMA='$schema$' AND COLUMN_NAME = '$column$')\r\nBEGIN\r\n\tALTER TABLE $schema$.$table$ ADD $column$ $type$ NOT NULL;\r\nEND ",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "schema",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "table",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "column",
|
||||
"defaultValue": null
|
||||
},
|
||||
{
|
||||
"name": "type",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "06e0e196-f6a3-4ae9-aea2-43ec5910821a",
|
||||
"prefix": "nl",
|
||||
"description": "",
|
||||
"body": "WITH(NOLOCK)"
|
||||
{
|
||||
"id": "06e0e196-f6a3-4ae9-aea2-43ec5910821a",
|
||||
"prefix": "nl",
|
||||
"description": "",
|
||||
"body": "WITH(NOLOCK)"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "94dc16da-08e3-46ca-b4b7-0325b252d35c",
|
||||
"prefix": "ob",
|
||||
"description": "ORDER BY fragment",
|
||||
"body": "ORDER BY "
|
||||
{
|
||||
"id": "94dc16da-08e3-46ca-b4b7-0325b252d35c",
|
||||
"prefix": "ob",
|
||||
"description": "ORDER BY fragment",
|
||||
"body": "ORDER BY "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "fd320b21-00b9-41dc-a72a-0c9a90d1e259",
|
||||
"prefix": "opts",
|
||||
"description": "connection options set",
|
||||
"body": "DECLARE @options INT\r\nSELECT @options = @@OPTIONS\r\n\r\nPRINT 'Current option value: '+CONVERT(VARCHAR(10), @options)\r\nIF ( (1 & @options) = 1 ) PRINT 'DISABLE_DEF_CNST_CHK'\r\nIF ( (2 & @options) = 2 ) PRINT 'IMPLICIT_TRANSACTIONS'\r\nIF ( (4 & @options) = 4 ) PRINT 'CURSOR_CLOSE_ON_COMMIT'\r\nIF ( (8 & @options) = 8 ) PRINT 'ANSI_WARNINGS'\r\nIF ( (16 & @options) = 16 ) PRINT 'ANSI_PADDING'\r\nIF ( (32 & @options) = 32 ) PRINT 'ANSI_NULLS'\r\nIF ( (64 & @options) = 64 ) PRINT 'ARITHABORT'\r\nIF ( (128 & @options) = 128 ) PRINT 'ARITHIGNORE'\r\nIF ( (256 & @options) = 256 ) PRINT 'QUOTED_IDENTIFIER'\r\nIF ( (512 & @options) = 512 ) PRINT 'NOCOUNT'\r\nIF ( (1024 & @options) = 1024 ) PRINT 'ANSI_NULL_DFLT_ON'\r\nIF ( (2048 & @options) = 2048 ) PRINT 'ANSI_NULL_DFLT_OFF'\r\nIF ( (4096 & @options) = 4096 ) PRINT 'CONCAT_NULL_YIELDS_NULL'\r\nIF ( (8192 & @options) = 8192 ) PRINT 'NUMERIC_ROUNDABORT'\r\nIF ( (16384 & @options) = 16384 ) PRINT 'XACT_ABORT' \r\n"
|
||||
{
|
||||
"id": "fd320b21-00b9-41dc-a72a-0c9a90d1e259",
|
||||
"prefix": "opts",
|
||||
"description": "connection options set",
|
||||
"body": "DECLARE @options INT\r\nSELECT @options = @@OPTIONS\r\n\r\nPRINT 'Current option value: '+CONVERT(VARCHAR(10), @options)\r\nIF ( (1 & @options) = 1 ) PRINT 'DISABLE_DEF_CNST_CHK'\r\nIF ( (2 & @options) = 2 ) PRINT 'IMPLICIT_TRANSACTIONS'\r\nIF ( (4 & @options) = 4 ) PRINT 'CURSOR_CLOSE_ON_COMMIT'\r\nIF ( (8 & @options) = 8 ) PRINT 'ANSI_WARNINGS'\r\nIF ( (16 & @options) = 16 ) PRINT 'ANSI_PADDING'\r\nIF ( (32 & @options) = 32 ) PRINT 'ANSI_NULLS'\r\nIF ( (64 & @options) = 64 ) PRINT 'ARITHABORT'\r\nIF ( (128 & @options) = 128 ) PRINT 'ARITHIGNORE'\r\nIF ( (256 & @options) = 256 ) PRINT 'QUOTED_IDENTIFIER'\r\nIF ( (512 & @options) = 512 ) PRINT 'NOCOUNT'\r\nIF ( (1024 & @options) = 1024 ) PRINT 'ANSI_NULL_DFLT_ON'\r\nIF ( (2048 & @options) = 2048 ) PRINT 'ANSI_NULL_DFLT_OFF'\r\nIF ( (4096 & @options) = 4096 ) PRINT 'CONCAT_NULL_YIELDS_NULL'\r\nIF ( (8192 & @options) = 8192 ) PRINT 'NUMERIC_ROUNDABORT'\r\nIF ( (16384 & @options) = 16384 ) PRINT 'XACT_ABORT' \r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "59cf80eb-b43b-4e5a-9e33-3dbcc1102c6c",
|
||||
"prefix": "percent",
|
||||
"description": "% of operation (BKP, RESTORE, COMPACT)",
|
||||
"body": "SELECT [r].[session_id],\r\n [r].[command],\r\n CONVERT(NUMERIC(6, 2), [r].[percent_complete]) AS [Percent Complete],\r\n CONVERT(VARCHAR(20), DATEADD(ms, [r].[estimated_completion_time], GETDATE()), 20) AS [ETA Completion Time],\r\n CONVERT(NUMERIC(10, 2), [r].[total_elapsed_time] / 1000.0 / 60.0) AS [Elapsed Min],\r\n CONVERT(NUMERIC(10, 2), [r].[estimated_completion_time] / 1000.0 / 60.0) AS [ETA Min],\r\n CONVERT(NUMERIC(10, 2), [r].[estimated_completion_time] / 1000.0 / 60.0 / 60.0) AS [ETA Hours],\r\n CONVERT(\r\n VARCHAR(1000),\r\n ( SELECT SUBSTRING(\r\n text,\r\n r.statement_start_offset / 2,\r\n CASE\r\n WHEN r.statement_end_offset = -1 THEN 1000\r\n ELSE (r.statement_end_offset - r.statement_start_offset) / 2 END)\r\n FROM sys.dm_exec_sql_text(sql_handle) )) AS [SQL]\r\n FROM sys.dm_exec_requests r\r\nWHERE [r].[command] IN ( 'RESTORE DATABASE', 'BACKUP DATABASE', 'DbccFilesCompact', 'DbccSpaceReclaim' );\r\n\r\n"
|
||||
{
|
||||
"id": "59cf80eb-b43b-4e5a-9e33-3dbcc1102c6c",
|
||||
"prefix": "percent",
|
||||
"description": "% of operation (BKP, RESTORE, COMPACT)",
|
||||
"body": "SELECT [r].[session_id],\r\n [r].[command],\r\n CONVERT(NUMERIC(6, 2), [r].[percent_complete]) AS [Percent Complete],\r\n CONVERT(VARCHAR(20), DATEADD(ms, [r].[estimated_completion_time], GETDATE()), 20) AS [ETA Completion Time],\r\n CONVERT(NUMERIC(10, 2), [r].[total_elapsed_time] / 1000.0 / 60.0) AS [Elapsed Min],\r\n CONVERT(NUMERIC(10, 2), [r].[estimated_completion_time] / 1000.0 / 60.0) AS [ETA Min],\r\n CONVERT(NUMERIC(10, 2), [r].[estimated_completion_time] / 1000.0 / 60.0 / 60.0) AS [ETA Hours],\r\n CONVERT(\r\n VARCHAR(1000),\r\n ( SELECT SUBSTRING(\r\n text,\r\n r.statement_start_offset / 2,\r\n CASE\r\n WHEN r.statement_end_offset = -1 THEN 1000\r\n ELSE (r.statement_end_offset - r.statement_start_offset) / 2 END)\r\n FROM sys.dm_exec_sql_text(sql_handle) )) AS [SQL]\r\n FROM sys.dm_exec_requests r\r\nWHERE [r].[command] IN ( 'RESTORE DATABASE', 'BACKUP DATABASE', 'DbccFilesCompact', 'DbccSpaceReclaim' );\r\n\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "2de5009b-c299-46aa-ac66-f1019d24ed05",
|
||||
"prefix": "pharmacy_code",
|
||||
"description": "fetch pharmacy code from a pharmacy",
|
||||
"body": "SELECT DISTINCT [dh].[DH_pharmacy_code]\r\nFROM [Arizona].[dbo].[Document_header] [dh]"
|
||||
{
|
||||
"id": "2de5009b-c299-46aa-ac66-f1019d24ed05",
|
||||
"prefix": "pharmacy_code",
|
||||
"description": "fetch pharmacy code from a pharmacy",
|
||||
"body": "SELECT DISTINCT [dh].[DH_pharmacy_code]\r\nFROM [Arizona].[dbo].[Document_header] [dh]"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "349bfc81-104e-44ab-afc5-f1cf8adaea6b",
|
||||
"prefix": "plan",
|
||||
"description": "fetch query plan from cache",
|
||||
"body": "SELECT [text]\r\n\t,cp.size_in_bytes\r\n\t,plan_handle\r\nFROM sys.dm_exec_cached_plans AS cp\r\nCROSS APPLY sys.dm_exec_sql_text(plan_handle)\r\nWHERE cp.cacheobjtype = N'Compiled Plan'\r\n\tAND cp.objtype = N'Adhoc'\r\n\tAND cp.usecounts = 1\r\n--AND [text] LIKE '%tblChecksum%'\r\nORDER BY cp.size_in_bytes DESC;\r\n"
|
||||
{
|
||||
"id": "349bfc81-104e-44ab-afc5-f1cf8adaea6b",
|
||||
"prefix": "plan",
|
||||
"description": "fetch query plan from cache",
|
||||
"body": "SELECT [text]\r\n\t,cp.size_in_bytes\r\n\t,plan_handle\r\nFROM sys.dm_exec_cached_plans AS cp\r\nCROSS APPLY sys.dm_exec_sql_text(plan_handle)\r\nWHERE cp.cacheobjtype = N'Compiled Plan'\r\n\tAND cp.objtype = N'Adhoc'\r\n\tAND cp.usecounts = 1\r\n--AND [text] LIKE '%tblChecksum%'\r\nORDER BY cp.size_in_bytes DESC;\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "678da7f8-3efa-4e3e-810b-01ae866ea4b5",
|
||||
"prefix": "ple",
|
||||
"description": "get current page life expectancy",
|
||||
"body": "SELECT \r\n\tobject_name\r\n\t,counter_name\r\n\t,value\t\t\t= cntr_value\r\nFROM sys.dm_os_performance_counters\r\nWHERE 1=1\r\nAND LTRIM(RTRIM(object_name)) LIKE '%:Buffer Manager'\r\nAND LTRIM(RTRIM(counter_name)) = 'Page life expectancy' \r\n"
|
||||
{
|
||||
"id": "678da7f8-3efa-4e3e-810b-01ae866ea4b5",
|
||||
"prefix": "ple",
|
||||
"description": "get current page life expectancy",
|
||||
"body": "SELECT \r\n\tobject_name\r\n\t,counter_name\r\n\t,value\t\t\t= cntr_value\r\nFROM sys.dm_os_performance_counters\r\nWHERE 1=1\r\nAND LTRIM(RTRIM(object_name)) LIKE '%:Buffer Manager'\r\nAND LTRIM(RTRIM(counter_name)) = 'Page life expectancy' \r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "54378923-de49-4c06-81a4-ab890719c1a4",
|
||||
"prefix": "pos_clean_repli_checks",
|
||||
"description": "kill all query doing a replication check from the pos, so that the replication can work",
|
||||
"body": "DECLARE @kill VARCHAR(8000);\r\nSET @kill = '';\r\nSELECT @kill = @kill + 'kill ' + CONVERT(VARCHAR(5), session_id) + ';'\r\n FROM sys.dm_exec_requests\r\n CROSS APPLY sys.dm_exec_sql_text(sql_handle)\r\n WHERE database_id = DB_ID('activepos_write')\r\n AND session_id <> @@SPID\r\n AND text LIKE '%AND NOT EXISTS (SELECT * FROM vw_T_Sales_Order_header%';\r\n--EXEC(@kill);\r\n\r\nPRINT @kill;"
|
||||
{
|
||||
"id": "54378923-de49-4c06-81a4-ab890719c1a4",
|
||||
"prefix": "pos_clean_repli_checks",
|
||||
"description": "kill all query doing a replication check from the pos, so that the replication can work",
|
||||
"body": "DECLARE @kill VARCHAR(8000);\r\nSET @kill = '';\r\nSELECT @kill = @kill + 'kill ' + CONVERT(VARCHAR(5), session_id) + ';'\r\n FROM sys.dm_exec_requests\r\n CROSS APPLY sys.dm_exec_sql_text(sql_handle)\r\n WHERE database_id = DB_ID('activepos_write')\r\n AND session_id <> @@SPID\r\n AND text LIKE '%AND NOT EXISTS (SELECT * FROM vw_T_Sales_Order_header%';\r\n--EXEC(@kill);\r\n\r\nPRINT @kill;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "3b355313-2d70-4420-90fc-d6976eef283a",
|
||||
"prefix": "pt",
|
||||
"description": "",
|
||||
"body": "PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - $CURSOR$';\r\n"
|
||||
{
|
||||
"id": "3b355313-2d70-4420-90fc-d6976eef283a",
|
||||
"prefix": "pt",
|
||||
"description": "",
|
||||
"body": "PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - $CURSOR$';\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "04440efb-13a7-42c3-833f-7d9f30c90ff3",
|
||||
"prefix": "ptc",
|
||||
"description": "",
|
||||
"body": "PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - $CURSOR$. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';\r\n"
|
||||
{
|
||||
"id": "04440efb-13a7-42c3-833f-7d9f30c90ff3",
|
||||
"prefix": "ptc",
|
||||
"description": "",
|
||||
"body": "PRINT CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 114)+' - $CURSOR$. '+REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, @@rowcount), 1),',',''''),'.00','')+' row(s) affected.';\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "2f90e674-1d0d-4ad7-9238-12e184767a4c",
|
||||
"prefix": "pval",
|
||||
"description": "",
|
||||
"body": "'+ISNULL(CONVERT(VARCHAR(200),$CURSOR$),'NULL')+'"
|
||||
{
|
||||
"id": "2f90e674-1d0d-4ad7-9238-12e184767a4c",
|
||||
"prefix": "pval",
|
||||
"description": "",
|
||||
"body": "'+ISNULL(CONVERT(VARCHAR(200),$CURSOR$),'NULL')+'"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "32fd4a4f-53d3-4bb1-aa70-ee59e64426c9",
|
||||
"prefix": "query_store_enable",
|
||||
"description": "",
|
||||
"body": "DECLARE @tpl VARCHAR(444) = 'ALTER DATABASE @db@ SET QUERY_STORE = ON;'\r\n\r\nSELECT name, REPLACE(@tpl, '@db@', d.[name]) AS q, *\r\nFROM sys.databases d\r\nWHERE [d].[database_id]>4 --no system db's\r\nAND d.[is_read_only] = 0 --RW db's only\r\nAND d.[state] = 0 --online\r\n"
|
||||
{
|
||||
"id": "32fd4a4f-53d3-4bb1-aa70-ee59e64426c9",
|
||||
"prefix": "query_store_enable",
|
||||
"description": "",
|
||||
"body": "DECLARE @tpl VARCHAR(444) = 'ALTER DATABASE @db@ SET QUERY_STORE = ON;'\r\n\r\nSELECT name, REPLACE(@tpl, '@db@', d.[name]) AS q, *\r\nFROM sys.databases d\r\nWHERE [d].[database_id]>4 --no system db's\r\nAND d.[is_read_only] = 0 --RW db's only\r\nAND d.[state] = 0 --online\r\n"
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"id": "f1c69117-2ba6-46d4-a3b6-ef957ac692fb",
|
||||
"prefix": "reg",
|
||||
"description": "",
|
||||
"body": "--#region $name$\r\n--#endregion $name$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "name",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "f1c69117-2ba6-46d4-a3b6-ef957ac692fb",
|
||||
"prefix": "reg",
|
||||
"description": "",
|
||||
"body": "--#region $name$\r\n--#endregion $name$",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "name",
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "8c60aa30-593b-4050-b490-044f10ecd07f",
|
||||
"prefix": "repl",
|
||||
"description": "POS replication ",
|
||||
"body": "SELECT [pos].[POS_hostname], [pos].[POS_MAC_address], [pos].[POS_number], [pos].[POS_type]\r\nFROM [Arizona].[dbo].[Point_of_sale] [pos]\r\nWHERE [pos].[POS_active]=1\r\nAND [pos].[POS_type] IN (1,2)\r\nAND [pos].[POS_number] < 99\r\nORDER BY [pos].[POS_number]\r\n;\r\n\r\nSELECT ActivePos_write.upd.DatabaseVersion() AS currentVersion;\r\n\r\nSELECT SettingValue AS backupSrc\r\n FROM ActiveSystemServer.cfg.Settings\r\n WHERE SettingId LIKE 'Values.Modules.Replication.DbInitializationBackupPath%'\r\n AND LEN(SettingValue) > 1;\r\n\r\n--last backup\r\nSELECT\r\n JobName = J.name,\r\n H.*\r\nFROM\r\n msdb.dbo.sysjobs AS J\r\n CROSS APPLY (\r\n SELECT TOP 20\r\n JobName = J.name,\r\n StepNumber = T.step_id,\r\n StepName = T.step_name,\r\n StepStatus = CASE T.run_status\r\n WHEN 0 THEN 'Failed'\r\n WHEN 1 THEN 'Succeeded'\r\n WHEN 2 THEN 'Retry'\r\n WHEN 3 THEN 'Canceled'\r\n ELSE 'Running' END,\r\n ExecutedAt = msdb.dbo.agent_datetime(T.run_date, T.run_time),\r\n ExecutingHours = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) / 60,\r\n ExecutingMinutes = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) % 60,\r\n Message = T.message\r\n ,t.[instance_id]\r\n FROM msdb.dbo.sysjobhistory AS T\r\n WHERE T.job_id = J.job_id\r\n ORDER BY t.[instance_id] DESC\r\n ) AS H\r\nWHERE [J].[name]='D91030 - Backup ActivePos_Read'\r\nAND [H].[StepNumber] = 0\r\nORDER BY J.name\r\n\r\nRETURN\r\n\r\n--start backup\r\nEXEC msdb.dbo.sp_start_job @job_name = N'D91030 - Backup ActivePos_Read' , @step_name = 'Purge old ActivePos_Read backups'\r\n\r\nWAITFOR DELAY '00:00:05.000'\r\n\r\nWHILE EXISTS(\r\n SELECT sj.name\r\n , sja.*\r\n FROM msdb.dbo.sysjobactivity AS sja\r\n INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id\r\n WHERE sj.[name]='D91030 - Backup ActivePos_Read'\r\n AND sja.start_execution_date IS NOT NULL\r\n AND sja.stop_execution_date IS NULL\r\n) BEGIN\r\n --PRINT 'job is still running '+CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n DECLARE @t VARCHAR(20) = CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n RAISERROR('%s, job is still running', 0, 1, @t) WITH NOWAIT;\r\n WAITFOR DELAY '00:00:05.000'\r\nEND \r\n\r\n--check POS and PHCY versions\r\nSELECT ActivePos_write.upd.DatabaseVersion() AS currentVersion\r\nEXEC ('SELECT ActivePos_write.upd.DatabaseVersion()') AT xxx\r\n\r\n--force restore after manual copy\r\nEXEC ('exec ActivePos_write.dbo.InitializeActivePosReadFromBackup @BackUpFileWithPath = ''c:\\temp\\ActivePos_read.22.1.223.2401.bak''') AT xxx\r\n\r\n--to start on the pos to force a restore of the backup. adapt version, mac and UNC before running\r\nexec ActiveSystemClient.dbo.DBAReplPosSubscription \r\n\t @mac = '9C-7B-EF-43-5A-98', \r\n\t @serverDbVersion = '23.2.23.19501', \r\n\t @preferedReplinibackup= '\\\\cvi247aps-replinibackup.coop-vitality.ch\\replinibackup\\ActivePos_read.23.2.23.19501.bak'\r\n\r\n\r\n--restart service on pos\r\nEXEC ('EXEC xp_cmdshell ''net stop ActiveposClientService'';EXEC xp_cmdshell ''net start ActiveposClientService''') AT xxx\r\n\r\n--subscription\r\nEXEC ActivePos_read..sp_dropsubscription @publication = N'ActivePosTran', @article = N'all', @subscriber ='xxx'\r\nEXEC ActiveSystemServer.dbo.RepairReplication\r\n"
|
||||
{
|
||||
"id": "8c60aa30-593b-4050-b490-044f10ecd07f",
|
||||
"prefix": "repl",
|
||||
"description": "POS replication ",
|
||||
"body": "SELECT [pos].[POS_hostname], [pos].[POS_MAC_address], [pos].[POS_number], [pos].[POS_type]\r\nFROM [Arizona].[dbo].[Point_of_sale] [pos]\r\nWHERE [pos].[POS_active]=1\r\nAND [pos].[POS_type] IN (1,2)\r\nAND [pos].[POS_number] < 99\r\nORDER BY [pos].[POS_number]\r\n;\r\n\r\nSELECT ActivePos_write.upd.DatabaseVersion() AS currentVersion;\r\n\r\nSELECT SettingValue AS backupSrc\r\n FROM ActiveSystemServer.cfg.Settings\r\n WHERE SettingId LIKE 'Values.Modules.Replication.DbInitializationBackupPath%'\r\n AND LEN(SettingValue) > 1;\r\n\r\n--last backup\r\nSELECT\r\n JobName = J.name,\r\n H.*\r\nFROM\r\n msdb.dbo.sysjobs AS J\r\n CROSS APPLY (\r\n SELECT TOP 20\r\n JobName = J.name,\r\n StepNumber = T.step_id,\r\n StepName = T.step_name,\r\n StepStatus = CASE T.run_status\r\n WHEN 0 THEN 'Failed'\r\n WHEN 1 THEN 'Succeeded'\r\n WHEN 2 THEN 'Retry'\r\n WHEN 3 THEN 'Canceled'\r\n ELSE 'Running' END,\r\n ExecutedAt = msdb.dbo.agent_datetime(T.run_date, T.run_time),\r\n ExecutingHours = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) / 60,\r\n ExecutingMinutes = ((T.run_duration/10000 * 3600 + (T.run_duration/100) % 100 * 60 + T.run_duration % 100 + 31 ) / 60) % 60,\r\n Message = T.message\r\n ,t.[instance_id]\r\n FROM msdb.dbo.sysjobhistory AS T\r\n WHERE T.job_id = J.job_id\r\n ORDER BY t.[instance_id] DESC\r\n ) AS H\r\nWHERE [J].[name]='D91030 - Backup ActivePos_Read'\r\nAND [H].[StepNumber] = 0\r\nORDER BY J.name\r\n\r\nRETURN\r\n\r\n--start backup\r\nEXEC msdb.dbo.sp_start_job @job_name = N'D91030 - Backup ActivePos_Read' , @step_name = 'Purge old ActivePos_Read backups'\r\n\r\nWAITFOR DELAY '00:00:05.000'\r\n\r\nWHILE EXISTS(\r\n SELECT sj.name\r\n , sja.*\r\n FROM msdb.dbo.sysjobactivity AS sja\r\n INNER JOIN msdb.dbo.sysjobs AS sj ON sja.job_id = sj.job_id\r\n WHERE sj.[name]='D91030 - Backup ActivePos_Read'\r\n AND sja.start_execution_date IS NOT NULL\r\n AND sja.stop_execution_date IS NULL\r\n) BEGIN\r\n --PRINT 'job is still running '+CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n DECLARE @t VARCHAR(20) = CONVERT(VARCHAR(20), CURRENT_TIMESTAMP, 120);\r\n RAISERROR('%s, job is still running', 0, 1, @t) WITH NOWAIT;\r\n WAITFOR DELAY '00:00:05.000'\r\nEND \r\n\r\n--check POS and PHCY versions\r\nSELECT ActivePos_write.upd.DatabaseVersion() AS currentVersion\r\nEXEC ('SELECT ActivePos_write.upd.DatabaseVersion()') AT xxx\r\n\r\n--force restore after manual copy\r\nEXEC ('exec ActivePos_write.dbo.InitializeActivePosReadFromBackup @BackUpFileWithPath = ''c:\\temp\\ActivePos_read.22.1.223.2401.bak''') AT xxx\r\n\r\n--to start on the pos to force a restore of the backup. adapt version, mac and UNC before running\r\nexec ActiveSystemClient.dbo.DBAReplPosSubscription \r\n\t @mac = '9C-7B-EF-43-5A-98', \r\n\t @serverDbVersion = '23.2.23.19501', \r\n\t @preferedReplinibackup= '\\\\cvi247aps-replinibackup.coop-vitality.ch\\replinibackup\\ActivePos_read.23.2.23.19501.bak'\r\n\r\n\r\n--restart service on pos\r\nEXEC ('EXEC xp_cmdshell ''net stop ActiveposClientService'';EXEC xp_cmdshell ''net start ActiveposClientService''') AT xxx\r\n\r\n--subscription\r\nEXEC ActivePos_read..sp_dropsubscription @publication = N'ActivePosTran', @article = N'all', @subscriber ='xxx'\r\nEXEC ActiveSystemServer.dbo.RepairReplication\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "f4a33a56-bbd3-4585-9038-bf8d52dc876c",
|
||||
"prefix": "ret",
|
||||
"description": "",
|
||||
"body": "return"
|
||||
{
|
||||
"id": "f4a33a56-bbd3-4585-9038-bf8d52dc876c",
|
||||
"prefix": "ret",
|
||||
"description": "",
|
||||
"body": "return"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "388131b5-079c-4b86-8dd7-e92c403babf8",
|
||||
"prefix": "rj",
|
||||
"description": "RIGHT JOIN fragment",
|
||||
"body": "RIGHT JOIN "
|
||||
{
|
||||
"id": "388131b5-079c-4b86-8dd7-e92c403babf8",
|
||||
"prefix": "rj",
|
||||
"description": "RIGHT JOIN fragment",
|
||||
"body": "RIGHT JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "a34a0f62-e0c5-49e2-a41d-181da6aa288d",
|
||||
"prefix": "roj",
|
||||
"description": "RIGHT OUTER JOIN fragment",
|
||||
"body": "RIGHT OUTER JOIN "
|
||||
{
|
||||
"id": "a34a0f62-e0c5-49e2-a41d-181da6aa288d",
|
||||
"prefix": "roj",
|
||||
"description": "RIGHT OUTER JOIN fragment",
|
||||
"body": "RIGHT OUTER JOIN "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "f3809a25-f817-475f-9f45-39ea588477dc",
|
||||
"prefix": "rt",
|
||||
"description": "Rollback transaction",
|
||||
"body": "ROLLBACK TRANSACTION "
|
||||
{
|
||||
"id": "f3809a25-f817-475f-9f45-39ea588477dc",
|
||||
"prefix": "rt",
|
||||
"description": "Rollback transaction",
|
||||
"body": "ROLLBACK TRANSACTION "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "337977e4-5af3-4c42-9cff-7e2059961365",
|
||||
"prefix": "scf",
|
||||
"description": "Count number of records returned by query",
|
||||
"body": "SELECT COUNT(*) FROM "
|
||||
{
|
||||
"id": "337977e4-5af3-4c42-9cff-7e2059961365",
|
||||
"prefix": "scf",
|
||||
"description": "Count number of records returned by query",
|
||||
"body": "SELECT COUNT(*) FROM "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "0970ec7e-b7c0-4a04-be1d-c4cc12ec73a7",
|
||||
"prefix": "searchCode",
|
||||
"description": "Search through procs, functions and trigger a specific keyword. Avoid to check out a repo to do that search.",
|
||||
"body": "SET TRAN ISOLATION LEVEL READ UNCOMMITTED\r\n\r\nDECLARE\r\n @SEARCHSTRING VARCHAR(255)\r\n ,@notcontain VARCHAR(255);\r\n\r\nSELECT\r\n @SEARCHSTRING = '$CURSOR$'\r\n ,@notcontain = '';\r\n\r\nSELECT DISTINCT\r\n sysobjects.name AS [Object Name]\r\n ,CASE\r\n WHEN sysobjects.xtype = 'P' THEN 'Stored Proc'\r\n WHEN sysobjects.xtype = 'TF' THEN 'Function'\r\n WHEN sysobjects.xtype = 'TR' THEN 'Trigger'\r\n END AS [Object Type]\r\nFROM sysobjects\r\n ,syscomments\r\nWHERE sysobjects.id = syscomments.id\r\nAND sysobjects.type IN ( 'P', 'TF', 'TR' )\r\nAND sysobjects.category = 0\r\nAND CHARINDEX(@SEARCHSTRING, syscomments.text) > 0\r\nAND ((\r\n CHARINDEX(@notcontain, syscomments.text) = 0\r\n OR CHARINDEX(@notcontain, syscomments.text) <> 0\r\n )\r\n);"
|
||||
{
|
||||
"id": "0970ec7e-b7c0-4a04-be1d-c4cc12ec73a7",
|
||||
"prefix": "searchCode",
|
||||
"description": "Search through procs, functions and trigger a specific keyword. Avoid to check out a repo to do that search.",
|
||||
"body": "SET TRAN ISOLATION LEVEL READ UNCOMMITTED\r\n\r\nDECLARE\r\n @SEARCHSTRING VARCHAR(255)\r\n ,@notcontain VARCHAR(255);\r\n\r\nSELECT\r\n @SEARCHSTRING = '$CURSOR$'\r\n ,@notcontain = '';\r\n\r\nSELECT DISTINCT\r\n sysobjects.name AS [Object Name]\r\n ,CASE\r\n WHEN sysobjects.xtype = 'P' THEN 'Stored Proc'\r\n WHEN sysobjects.xtype = 'TF' THEN 'Function'\r\n WHEN sysobjects.xtype = 'TR' THEN 'Trigger'\r\n END AS [Object Type]\r\nFROM sysobjects\r\n ,syscomments\r\nWHERE sysobjects.id = syscomments.id\r\nAND sysobjects.type IN ( 'P', 'TF', 'TR' )\r\nAND sysobjects.category = 0\r\nAND CHARINDEX(@SEARCHSTRING, syscomments.text) > 0\r\nAND ((\r\n CHARINDEX(@notcontain, syscomments.text) = 0\r\n OR CHARINDEX(@notcontain, syscomments.text) <> 0\r\n )\r\n);"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "65cd3b01-5d90-454e-a523-dbb80156d2c6",
|
||||
"prefix": "seria",
|
||||
"description": "change temporarily the isolation mode, get back to initial mode afterward",
|
||||
"body": "DECLARE @initialIsolation VARCHAR(50);\r\nSELECT @initialIsolation = CASE transaction_isolation_level \r\n\t\tWHEN 0 THEN 'Unspecified' \r\n\t\tWHEN 1 THEN 'ReadUncommitted' \r\n\t\tWHEN 2 THEN 'ReadCommitted' \r\n\t\tWHEN 3 THEN 'Repeatable' \r\n\t\tWHEN 4 THEN 'Serializable' \r\n\t\tWHEN 5 THEN 'Snapshot' \r\n\tEND \r\nFROM sys.dm_exec_sessions \r\nwhere session_id = @@SPID;\r\n\r\nSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;\r\n$CURSOR$\r\nEXEC('SET TRANSACTION ISOLATION LEVEL '+@initialIsolation+';');\r\n"
|
||||
{
|
||||
"id": "65cd3b01-5d90-454e-a523-dbb80156d2c6",
|
||||
"prefix": "seria",
|
||||
"description": "change temporarily the isolation mode, get back to initial mode afterward",
|
||||
"body": "DECLARE @initialIsolation VARCHAR(50);\r\nSELECT @initialIsolation = CASE transaction_isolation_level \r\n\t\tWHEN 0 THEN 'Unspecified' \r\n\t\tWHEN 1 THEN 'ReadUncommitted' \r\n\t\tWHEN 2 THEN 'ReadCommitted' \r\n\t\tWHEN 3 THEN 'Repeatable' \r\n\t\tWHEN 4 THEN 'Serializable' \r\n\t\tWHEN 5 THEN 'Snapshot' \r\n\tEND \r\nFROM sys.dm_exec_sessions \r\nwhere session_id = @@SPID;\r\n\r\nSET TRANSACTION ISOLATION LEVEL SERIALIZABLE;\r\n$CURSOR$\r\nEXEC('SET TRANSACTION ISOLATION LEVEL '+@initialIsolation+';');\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "d18e8e6b-64fd-44ac-acba-111a57d4f411",
|
||||
"prefix": "server_start_time",
|
||||
"description": "",
|
||||
"body": "SELECT a.[sqlserver_start_time], * \r\nFROM [sys].[dm_os_sys_info] a"
|
||||
{
|
||||
"id": "d18e8e6b-64fd-44ac-acba-111a57d4f411",
|
||||
"prefix": "server_start_time",
|
||||
"description": "",
|
||||
"body": "SELECT a.[sqlserver_start_time], * \r\nFROM [sys].[dm_os_sys_info] a"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "3a792d1a-98ee-4d0e-98f7-c44d4b158772",
|
||||
"prefix": "session_options",
|
||||
"description": "show current session options",
|
||||
"body": "with OPTION_VALUES as (\r\nselect\r\noptionValues.id,\r\noptionValues.name,\r\noptionValues.description,\r\nrow_number() over (partition by 1 order by id) as bitNum\r\nfrom (values\r\n(1, 'DISABLE_DEF_CNST_CHK', 'Controls interim or deferred constraint checking.'),\r\n(2, 'IMPLICIT_TRANSACTIONS', 'For dblib network library connections, controls whether a transaction is started implicitly when a statement is executed. The IMPLICIT_TRANSACTIONS setting has no effect on ODBC or OLEDB connections.'),\r\n(4, 'CURSOR_CLOSE_ON_COMMIT', 'Controls behavior of cursors after a commit operation has been performed.'),\r\n(8, 'ANSI_WARNINGS', 'Controls truncation and NULL in aggregate warnings.'),\r\n(16, 'ANSI_PADDING', 'Controls padding of fixed-length variables.'),\r\n(32, 'ANSI_NULLS', 'Controls NULL handling when using equality operators.'),\r\n(64, 'ARITHABORT', 'Terminates a query when an overflow or divide-by-zero error occurs during query execution.'),\r\n(128, 'ARITHIGNORE', 'Returns NULL when an overflow or divide-by-zero error occurs during a query.'),\r\n(256, 'QUOTED_IDENTIFIER', 'Differentiates between single and double quotation marks when evaluating an expression.'),\r\n(512, 'NOCOUNT', 'Turns off the message returned at the end of each statement that states how many rows were affected.'),\r\n(1024, 'ANSI_NULL_DFLT_ON', 'Alters the session'+char(39)+'s behavior to use ANSI compatibility for nullability. New columns defined without explicit nullability are defined to allow nulls.'),\r\n(2048, 'ANSI_NULL_DFLT_OFF', 'Alters the session'+char(39)+'s behavior not to use ANSI compatibility for nullability. New columns defined without explicit nullability do not allow nulls.'),\r\n(4096, 'CONCAT_NULL_YIELDS_NULL', 'Returns NULL when concatenating a NULL value with a string.'),\r\n(8192, 'NUMERIC_ROUNDABORT', 'Generates an error when a loss of precision occurs in an expression.'),\r\n(16384, 'XACT_ABORT', 'Rolls back a transaction if a Transact-SQL statement raises a run-time error.')\r\n) as optionValues(id, name, description)\r\n)\r\nselect *, case when (@@options & id) = id then 1 else 0 end as setting\r\nfrom OPTION_VALUES\r\nORDER BY [setting];"
|
||||
{
|
||||
"id": "3a792d1a-98ee-4d0e-98f7-c44d4b158772",
|
||||
"prefix": "session_options",
|
||||
"description": "show current session options",
|
||||
"body": "with OPTION_VALUES as (\r\nselect\r\noptionValues.id,\r\noptionValues.name,\r\noptionValues.description,\r\nrow_number() over (partition by 1 order by id) as bitNum\r\nfrom (values\r\n(1, 'DISABLE_DEF_CNST_CHK', 'Controls interim or deferred constraint checking.'),\r\n(2, 'IMPLICIT_TRANSACTIONS', 'For dblib network library connections, controls whether a transaction is started implicitly when a statement is executed. The IMPLICIT_TRANSACTIONS setting has no effect on ODBC or OLEDB connections.'),\r\n(4, 'CURSOR_CLOSE_ON_COMMIT', 'Controls behavior of cursors after a commit operation has been performed.'),\r\n(8, 'ANSI_WARNINGS', 'Controls truncation and NULL in aggregate warnings.'),\r\n(16, 'ANSI_PADDING', 'Controls padding of fixed-length variables.'),\r\n(32, 'ANSI_NULLS', 'Controls NULL handling when using equality operators.'),\r\n(64, 'ARITHABORT', 'Terminates a query when an overflow or divide-by-zero error occurs during query execution.'),\r\n(128, 'ARITHIGNORE', 'Returns NULL when an overflow or divide-by-zero error occurs during a query.'),\r\n(256, 'QUOTED_IDENTIFIER', 'Differentiates between single and double quotation marks when evaluating an expression.'),\r\n(512, 'NOCOUNT', 'Turns off the message returned at the end of each statement that states how many rows were affected.'),\r\n(1024, 'ANSI_NULL_DFLT_ON', 'Alters the session'+char(39)+'s behavior to use ANSI compatibility for nullability. New columns defined without explicit nullability are defined to allow nulls.'),\r\n(2048, 'ANSI_NULL_DFLT_OFF', 'Alters the session'+char(39)+'s behavior not to use ANSI compatibility for nullability. New columns defined without explicit nullability do not allow nulls.'),\r\n(4096, 'CONCAT_NULL_YIELDS_NULL', 'Returns NULL when concatenating a NULL value with a string.'),\r\n(8192, 'NUMERIC_ROUNDABORT', 'Generates an error when a loss of precision occurs in an expression.'),\r\n(16384, 'XACT_ABORT', 'Rolls back a transaction if a Transact-SQL statement raises a run-time error.')\r\n) as optionValues(id, name, description)\r\n)\r\nselect *, case when (@@options & id) = id then 1 else 0 end as setting\r\nfrom OPTION_VALUES\r\nORDER BY [setting];"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "c4978137-d293-4c35-9760-3dbfb2bfae23",
|
||||
"prefix": "sf",
|
||||
"description": "SELECT * FROM fragment",
|
||||
"body": "SELECT * \r\nFROM $CURSOR$"
|
||||
{
|
||||
"id": "c4978137-d293-4c35-9760-3dbfb2bfae23",
|
||||
"prefix": "sf",
|
||||
"description": "SELECT * FROM fragment",
|
||||
"body": "SELECT * \r\nFROM $CURSOR$"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "0b2557af-0b26-4c47-b15c-72a9d0314562",
|
||||
"prefix": "sql_start_time",
|
||||
"description": "",
|
||||
"body": "SELECT [sqlserver_start_time], [physical_memory_kb], [cpu_count]\r\nFROM sys.[dm_os_sys_info]"
|
||||
{
|
||||
"id": "0b2557af-0b26-4c47-b15c-72a9d0314562",
|
||||
"prefix": "sql_start_time",
|
||||
"description": "",
|
||||
"body": "SELECT [sqlserver_start_time], [physical_memory_kb], [cpu_count]\r\nFROM sys.[dm_os_sys_info]"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "a9bcbeb5-94ca-4ce8-a371-1c82a0662d19",
|
||||
"prefix": "st",
|
||||
"description": "SELECT top 100 rows",
|
||||
"body": "SELECT TOP (100) * FROM $CURSOR$"
|
||||
{
|
||||
"id": "a9bcbeb5-94ca-4ce8-a371-1c82a0662d19",
|
||||
"prefix": "st",
|
||||
"description": "SELECT top 100 rows",
|
||||
"body": "SELECT TOP (100) * FROM $CURSOR$"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "28526a01-97d7-4fc6-9e51-d7fc1764e6b3",
|
||||
"prefix": "stats",
|
||||
"description": "sql server statistics",
|
||||
"body": "SELECT DISTINCT OBJECT_NAME(s.[object_id]) AS TableName,\r\n c.name AS ColumnName,\r\n t.name AS tblName,\r\n s.name AS StatName,\r\n STATS_DATE(s.[object_id], s.stats_id) AS LastUpdated,\r\n DATEDIFF(d, STATS_DATE(s.[object_id], s.stats_id), GETDATE()) AS DaysOld,\r\n dsp.modification_counter,\r\n s.auto_created,\r\n s.user_created,\r\n s.no_recompute,\r\n s.[object_id],\r\n s.stats_id,\r\n sc.stats_column_id,\r\n sc.column_id\r\n FROM sys.stats s\r\n JOIN sys.stats_columns sc\r\n ON sc.[object_id] = s.[object_id]\r\n AND sc.stats_id = s.stats_id\r\n JOIN sys.columns c\r\n ON c.[object_id] = sc.[object_id]\r\n AND c.column_id = sc.column_id\r\n JOIN sys.tables t\r\n ON t.object_id = c.object_id\r\n JOIN sys.partitions par\r\n ON par.[object_id] = s.[object_id]\r\n JOIN sys.objects obj\r\n ON par.[object_id] = obj.[object_id]\r\n CROSS APPLY sys.dm_db_stats_properties(sc.[object_id], s.stats_id) AS dsp\r\n WHERE OBJECTPROPERTY(s.object_id, 'IsUserTable') = 1\r\n AND ( s.auto_created = 1\r\n OR s.user_created = 1)\r\n --AND t.name = 'Document_header'\r\n ORDER BY DaysOld;"
|
||||
{
|
||||
"id": "28526a01-97d7-4fc6-9e51-d7fc1764e6b3",
|
||||
"prefix": "stats",
|
||||
"description": "sql server statistics",
|
||||
"body": "SELECT DISTINCT OBJECT_NAME(s.[object_id]) AS TableName,\r\n c.name AS ColumnName,\r\n t.name AS tblName,\r\n s.name AS StatName,\r\n STATS_DATE(s.[object_id], s.stats_id) AS LastUpdated,\r\n DATEDIFF(d, STATS_DATE(s.[object_id], s.stats_id), GETDATE()) AS DaysOld,\r\n dsp.modification_counter,\r\n s.auto_created,\r\n s.user_created,\r\n s.no_recompute,\r\n s.[object_id],\r\n s.stats_id,\r\n sc.stats_column_id,\r\n sc.column_id\r\n FROM sys.stats s\r\n JOIN sys.stats_columns sc\r\n ON sc.[object_id] = s.[object_id]\r\n AND sc.stats_id = s.stats_id\r\n JOIN sys.columns c\r\n ON c.[object_id] = sc.[object_id]\r\n AND c.column_id = sc.column_id\r\n JOIN sys.tables t\r\n ON t.object_id = c.object_id\r\n JOIN sys.partitions par\r\n ON par.[object_id] = s.[object_id]\r\n JOIN sys.objects obj\r\n ON par.[object_id] = obj.[object_id]\r\n CROSS APPLY sys.dm_db_stats_properties(sc.[object_id], s.stats_id) AS dsp\r\n WHERE OBJECTPROPERTY(s.object_id, 'IsUserTable') = 1\r\n AND ( s.auto_created = 1\r\n OR s.user_created = 1)\r\n --AND t.name = 'Document_header'\r\n ORDER BY DaysOld;"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "ea735b8e-4db5-4048-bce6-c8dee79b5790",
|
||||
"prefix": "tc",
|
||||
"description": "TRY ... CATCH fragment",
|
||||
"body": "BEGIN TRY\r\n $SELECTEDTEXT$\r\nEND TRY\r\nBEGIN CATCH\r\n $CURSOR$\r\nEND CATCH"
|
||||
{
|
||||
"id": "ea735b8e-4db5-4048-bce6-c8dee79b5790",
|
||||
"prefix": "tc",
|
||||
"description": "TRY ... CATCH fragment",
|
||||
"body": "BEGIN TRY\r\n $SELECTEDTEXT$\r\nEND TRY\r\nBEGIN CATCH\r\n $CURSOR$\r\nEND CATCH"
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"id": "44e197f3-6a63-40ce-8e3c-1a1c18e4434d",
|
||||
"prefix": "timings",
|
||||
"description": "Wraps a simple timings test harness around the selected code",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2017\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/record-t-sql-execution-times-using-sql-prompt-snippet\r\n**/\r\n\r\nDECLARE @log table\r\n(\r\n TheOrder int IDENTITY(1, 1),\r\n WhatHappened varchar(200),\r\n WhenItDid datetime2 DEFAULT GETDATE()\r\n)\r\n----start of timing\r\nINSERT INTO @log(WhatHappened)\r\nSELECT 'Starting $routine$' --place at the start\r\n \r\n$SELECTEDTEXT$$CURSOR$\r\n \r\n--where the routine you want to time ends\r\nINSERT INTO @log(WhatHappened)\r\nSELECT '$routine$ took '\r\nSELECT ending.WhatHappened, DATEDIFF(ms, starting.WhenItDid, ending.WhenItDid)\r\nFROM @log starting\r\n INNER JOIN @log ending\r\n ON ending.TheOrder = starting.TheOrder + 1\r\n--list out all the timings",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "routine",
|
||||
"defaultValue": ""
|
||||
}
|
||||
]
|
||||
{
|
||||
"id": "44e197f3-6a63-40ce-8e3c-1a1c18e4434d",
|
||||
"prefix": "timings",
|
||||
"description": "Wraps a simple timings test harness around the selected code",
|
||||
"body": "/**\r\nCopyright (c) Red Gate Software Ltd 2017\r\nAll rights Reserved. Use of this code is subject to the terms of a license agreement with Red Gate Software Limited.\r\n\r\nFor more info, see https://www.red-gate.com/hub/product-learning/sql-prompt/record-t-sql-execution-times-using-sql-prompt-snippet\r\n**/\r\n\r\nDECLARE @log table\r\n(\r\n TheOrder int IDENTITY(1, 1),\r\n WhatHappened varchar(200),\r\n WhenItDid datetime2 DEFAULT GETDATE()\r\n)\r\n----start of timing\r\nINSERT INTO @log(WhatHappened)\r\nSELECT 'Starting $routine$' --place at the start\r\n \r\n$SELECTEDTEXT$$CURSOR$\r\n \r\n--where the routine you want to time ends\r\nINSERT INTO @log(WhatHappened)\r\nSELECT '$routine$ took '\r\nSELECT ending.WhatHappened, DATEDIFF(ms, starting.WhenItDid, ending.WhenItDid)\r\nFROM @log starting\r\n INNER JOIN @log ending\r\n ON ending.TheOrder = starting.TheOrder + 1\r\n--list out all the timings",
|
||||
"placeholders": [
|
||||
{
|
||||
"name": "routine",
|
||||
"defaultValue": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "0241a35e-0b6d-4056-8add-202af745a853",
|
||||
"prefix": "today",
|
||||
"description": "return the current date without time",
|
||||
"body": "DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0)"
|
||||
{
|
||||
"id": "0241a35e-0b6d-4056-8add-202af745a853",
|
||||
"prefix": "today",
|
||||
"description": "return the current date without time",
|
||||
"body": "DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0)"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "386e4ced-49f8-4a1c-8b35-0b68ae05ca17",
|
||||
"prefix": "tstamp",
|
||||
"description": "get timestamp",
|
||||
"body": "SELECT \r\n\tCONVERT(VARCHAR(4), DATEPART(YEAR, CURRENT_TIMESTAMP))\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(MONTH, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(DAY, CURRENT_TIMESTAMP)),2)\r\n\t+'_'\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(HOUR, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(MINUTE, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(SECOND, CURRENT_TIMESTAMP)),2)\r\n"
|
||||
{
|
||||
"id": "386e4ced-49f8-4a1c-8b35-0b68ae05ca17",
|
||||
"prefix": "tstamp",
|
||||
"description": "get timestamp",
|
||||
"body": "SELECT \r\n\tCONVERT(VARCHAR(4), DATEPART(YEAR, CURRENT_TIMESTAMP))\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(MONTH, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(DAY, CURRENT_TIMESTAMP)),2)\r\n\t+'_'\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(HOUR, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(MINUTE, CURRENT_TIMESTAMP)),2)\r\n\t+RIGHT('00'+CONVERT(VARCHAR(2), DATEPART(SECOND, CURRENT_TIMESTAMP)),2)\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "28ccb2a9-263a-46db-92e8-27d58971f114",
|
||||
"prefix": "version",
|
||||
"description": "get tripaharm version",
|
||||
"body": "--pharma\r\nSELECT ActivePos_write.upd.DatabaseVersion()\r\n\r\n--central\r\nSELECT TOP 3 * \r\nFROM arizona.dbo.APS_version_history h\r\nWHERE [h].[APSVH_program_name]='Arizona'\r\nAND [h].[APSVH_program_version] IS NOT NULL \r\nORDER BY [APSVH_APS_TS] DESC "
|
||||
{
|
||||
"id": "28ccb2a9-263a-46db-92e8-27d58971f114",
|
||||
"prefix": "version",
|
||||
"description": "get tripaharm version",
|
||||
"body": "--pharma\r\nSELECT ActivePos_write.upd.DatabaseVersion()\r\n\r\n--central\r\nSELECT TOP 3 * \r\nFROM arizona.dbo.APS_version_history h\r\nWHERE [h].[APSVH_program_name]='Arizona'\r\nAND [h].[APSVH_program_version] IS NOT NULL \r\nORDER BY [APSVH_APS_TS] DESC "
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "339f494d-8194-4fa6-b2b2-7133ecf49655",
|
||||
"prefix": "wac_old",
|
||||
"description": "call sp_whoIsActive",
|
||||
"body": "EXEC hciTools.dbo.sp_whoisactive\r\n @get_additional_info=0,@get_task_info=1, @output_column_list='[percent_complete][status][database_name][dd%][session_id][blocking_session_id][blocked_session_count][sql_text][sql_command][query_plan][login_name][wait_info][host_name][tasks][tran_log%][cpu%][temp%][block%][reads%][writes%][context%][physical%][locks][%]', @format_output=1\r\n ,@get_plans=0\r\n ,@get_outer_command=1\r\n ,@get_locks = 0\r\n ,@find_block_leaders = 1\t\r\n ,@sort_order = '[blocked_session_count] DESC,[session_id] ASC, [dd hh:mm:ss.mss] DESC';\r\n"
|
||||
{
|
||||
"id": "339f494d-8194-4fa6-b2b2-7133ecf49655",
|
||||
"prefix": "wac_old",
|
||||
"description": "call sp_whoIsActive",
|
||||
"body": "EXEC hciTools.dbo.sp_whoisactive\r\n @get_additional_info=0,@get_task_info=1, @output_column_list='[percent_complete][status][database_name][dd%][session_id][blocking_session_id][blocked_session_count][sql_text][sql_command][query_plan][login_name][wait_info][host_name][tasks][tran_log%][cpu%][temp%][block%][reads%][writes%][context%][physical%][locks][%]', @format_output=1\r\n ,@get_plans=0\r\n ,@get_outer_command=1\r\n ,@get_locks = 0\r\n ,@find_block_leaders = 1\t\r\n ,@sort_order = '[blocked_session_count] DESC,[session_id] ASC, [dd hh:mm:ss.mss] DESC';\r\n"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "7bce15ce-1e03-413c-8415-79fb5b0b6207",
|
||||
"prefix": "we",
|
||||
"description": "WHERE fragment",
|
||||
"body": "WHERE "
|
||||
{
|
||||
"id": "7bce15ce-1e03-413c-8415-79fb5b0b6207",
|
||||
"prefix": "we",
|
||||
"description": "WHERE fragment",
|
||||
"body": "WHERE "
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "10f68dd3-2117-403d-991a-1818c5e54098",
|
||||
"prefix": "xa",
|
||||
"description": "xact_abbort and nocount options",
|
||||
"body": "SET XACT_ABORT ON;\r\nSET NOCOUNT ON;\r\n"
|
||||
{
|
||||
"id": "10f68dd3-2117-403d-991a-1818c5e54098",
|
||||
"prefix": "xa",
|
||||
"description": "xact_abbort and nocount options",
|
||||
"body": "SET XACT_ABORT ON;\r\nSET NOCOUNT ON;\r\n"
|
||||
}
|
||||
Reference in New Issue
Block a user