This file contains hidden or 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
| SELECT | |
| ar.replica_server_name, | |
| adc.database_name, | |
| ag.name AS ag_name, | |
| drs.is_local, | |
| drs.is_primary_replica, | |
| drs.synchronization_state_desc, | |
| drs.is_commit_participant, | |
| drs.synchronization_health_desc, | |
| drs.recovery_lsn, |
This file contains hidden or 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
| exec sp_executesql N'WITH | |
| bucketizer as | |
| ( | |
| SELECT | |
| rs.plan_id as plan_id, | |
| rs.execution_type as execution_type, | |
| SUM(rs.count_executions) count_executions, | |
| DATEADD(d, ((DATEDIFF(d, 0, rs.last_execution_time))),0 ) as bucket_start, | |
| DATEADD(d, (1 + (DATEDIFF(d, 0, rs.last_execution_time))), 0) as bucket_end, | |
| ROUND(CONVERT(float, SUM(rs.avg_query_max_used_memory*rs.count_executions))/NULLIF(SUM(rs.count_executions), 0)*8,2) as avg_query_max_used_memory, |
This file contains hidden or 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 x | |
| AS ( SELECT local_database_name | |
| , remote_machine_name | |
| , role_desc | |
| , internal_state_desc | |
| , transfer_rate_bytes_per_second / 1024 / 1024 AS transfer_rate_MBps | |
| , transferred_size_bytes / 1024 / 1024 AS transferred_size_MB | |
| , database_size_bytes / 1024 / 1024 AS Database_Size_MB | |
| , is_compression_enabled | |
| FROM sys.dm_hadr_physical_seeding_stats ) |
This file contains hidden or 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
| SELECT --TOP 100 | |
| s.name + '.' + t.Name AS [Table Name], | |
| part.rows AS [Total Rows In Table - Modified], | |
| CAST((SUM( DISTINCT au.Total_pages) * 8 ) / 1024.000 / 1024.000 AS NUMERIC(18, 3)) | |
| AS [Table's Total Space In GB], | |
| 'ALTER TABLE [' + s.name + '].[' + t.Name + '] REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE, ONLINE=ON);' AS [daSQL] | |
| FROM | |
| SYS.Tables t INNER JOIN sys.schemas s ON t.schema_id = s.schema_id | |
| INNER JOIN SYS.Indexes idx ON t.Object_id = idx.Object_id |
This file contains hidden or 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 @SchemaName sysname = '' | |
| , @TableName sysname = ''; | |
| WITH pk /* Primary Keys */ | |
| AS ( SELECT t.object_id | |
| , pkc.column_id | |
| , ic.index_column_id pk_index | |
| , pk.name AS pk_name | |
| FROM sys.tables t | |
| JOIN sys.schemas s ON s.schema_id = t.schema_id |
This file contains hidden or 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
| import-module dbatools | |
| $TargetServer = "MyRemoteComputer" | |
| $regRoot = Get-DbaRegistryRoot -ComputerName $TargetServer | |
| # Reading a key | |
| Invoke-Command -ComputerName $regRoot.ComputerName -ScriptBlock { | |
| param($r) | |
| Get-ItemProperty -Path "$($r.RegistryRoot)\SQLServerAgent" -Name MSXEncryptChannelOptions | |
| } -ArgumentList $regRoot |
This file contains hidden or 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
| @startuml | |
| skinparam linetype ortho | |
| hide circle | |
| skinparam roundcorner 20 | |
| title AdventureWorks2017 | |
| Entity dbo.AWBuildVersion #62A9FF { | |
| * "SystemInformationID" : tinyint | |
| -- | |
| "Database Version" : nvarchar(25) |
This file contains hidden or 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
| param( | |
| $SqlInstance = 'SQLSRV01', | |
| $Database = "AdventureWorks2017" | |
| ) | |
| import-module dbatools; | |
| if ( $SqlInstance.GetType() -ne 'Server' ) { | |
| $inst = Connect-DbaInstance -SqlInstance $SqlInstance.ToString() | |
| } |
This file contains hidden or 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
| import-module dbatools | |
| $CMSInstance = "MyCMSInst" | |
| $Test2014Instance = "SQL2014" | |
| $Test2017Instance = "SQL2017" | |
| $InventoryInst = "MYINV" | |
| $InventoryDB = "DBATools" | |
| $InventoryTable = "BackupTestResults" | |
| Enum SQLVersionMajor { |
This file contains hidden or 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
| import-module dbatools | |
| Enum SQLVersionMajor { | |
| SQL2019 = 15 | |
| SQL2017 = 14 | |
| SQL2016 = 13 | |
| SQL2014 = 12 | |
| SQL2012 = 11 | |
| SQL2008 = 10 | |
| SQL2005 = 9 |