This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [WWI] | |
GO | |
ALTER DATABASE CURRENT SET QUERY_STORE (OPERATION_MODE = READ_WRITE, | |
QUERY_CAPTURE_MODE = ALL, | |
INTERVAL_LENGTH_MINUTES = 60) | |
ALTER DATABASE CURRENT SET QUERY_STORE CLEAR; | |
GO | |
SELECT * | |
FROM [Sales].[CustomerTransactions] | |
ORDER BY [TaxAmount] DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;WITH EdgeCTE | |
AS | |
( | |
SELECT parent_object_id Object1, | |
referenced_object_id Object2, | |
'[' + OBJECT_SCHEMA_NAME(FK.parent_object_id) + '].[' + OBJECT_NAME(FK.parent_object_id) + '] [T#L#1]' Table1, | |
'[' + OBJECT_SCHEMA_NAME(FK.referenced_object_id) + '].[' + OBJECT_NAME(FK.referenced_object_id) + '] [T#L#2]' Table2, | |
(SELECT CASE WHEN ROW_NUMBER() OVER(ORDER BY FKS.constraint_column_id) > 1 THEN ' AND ' ELSE '' END + | |
'[T#L#1].[' + C1.name + '] = ' + | |
'[T#L#2].[' + C2.name + ']' [text()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
# Built-in account | |
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection" | |
# Init variables (Automation Account variables) | |
$ResourceGroup = Get-AutomationVariable -Name 'ResourceGroup' | |
$SqlServerName = Get-AutomationVariable -Name 'SqlServerName' | |
$DatabaseName = Get-AutomationVariable -Name 'DatabaseName' | |
# Log into Azure with AzureRunAsConnection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;WITH TasksCTE | |
AS (SELECT session_id, | |
wait_type, | |
wait_duration_ms, | |
blocking_session_id, | |
resource_description, | |
PageID = CAST(Right(resource_description, LEN(resource_description)- | |
CHARINDEX(':', resource_description, 3)) As Int) | |
FROM sys.dm_os_waiting_tasks WITH (NOLOCK) | |
WHERE wait_type Like 'PAGE%LATCH_%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @ObjectId INT | |
SET @ObjectId = OBJECT_ID('SchemaName.TableName') | |
SELECT AU.*, | |
COALESCE(P1.object_id, P2.object_id) OBJECT_ID, | |
COALESCE(P1.index_id, P2.index_id) INDEX_ID | |
FROM sys.allocation_units AU | |
OUTER APPLY (SELECT TOP(1) P.object_id, | |
P.index_id | |
FROM sys.partitions P |
NewerOlder