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
| -- Primary and secondary | |
| select srvname | |
| FROM master.dbo.sysservers | |
| WHERE srvnetname IS NULL | |
| AND SUBSTRING( srvname, 1, 9 ) = SUBSTRING( @@SERVERNAME, 1, 9 ) | |
| AND srvid = 1; | |
| -- Mirrored dbs | |
| SELECT DB_NAME(database_id) As DatabaseName, | |
| CASE |
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
| SELECT | |
| session_id, | |
| start_time, | |
| status, | |
| command, | |
| percent_complete, | |
| estimated_completion_time, | |
| estimated_completion_time /60/1000 as estimate_completion_minutes, | |
| --(select convert(varchar(5),getdate(),8)), | |
| DATEADD(n,(estimated_completion_time /60/1000),GETDATE()) as estimated_completion_time |
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 msdb.dbo.sysmail_help_configure_sp; | |
| EXEC msdb.dbo.sysmail_help_account_sp; | |
| EXEC msdb.dbo.sysmail_help_profile_sp; | |
| EXEC msdb.dbo.sysmail_help_profileaccount_sp; | |
| EXEC msdb.dbo.sysmail_help_principalprofile_sp; |
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
| cluster group /status --shows Group, Node, Status | |
| cluster group "Cluster Group" /move | |
| cluster group "Available Storage" /move | |
| Alternatively output log with powershell, open cmd | |
| Powershell | |
| Import-Module FailoverClusters | |
| Get-ClusterLog -Destination c:\temp |
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
| [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null | |
| [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null | |
| $SQLInstance = "MyListener001" | |
| $AgName = Get-DbaAvailabilityGroup -SqlInstance $SQLInstance | Select-Object -ExpandProperty AvailabilityGroup | |
| $PrimaryReplica = Get-DbaAgReplica -SqlInstance $SQLInstance | Where-Object {$_.Role -eq "Primary" } | Select-Object -ExpandProperty Name | |
| $SecondaryReplica = Get-DbaAgReplica -SqlInstance $SQLInstance | Where-Object {$_.Role -eq "Secondary" } | Select-Object -ExpandProperty Name | |
| $Databases = ("Database01","Database02") |
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
| CREATE EVENT SESSION [Database_Growth_Watchdog] ON SERVER | |
| ADD EVENT sqlserver.database_file_size_change ( | |
| ACTION ( sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.session_nt_username, sqlserver.sql_text ) | |
| WHERE ( [database_id] = ( 31 ) ) | |
| ) | |
| ADD TARGET package0.event_file ( SET filename = 'F:\SQLDATA\MSSQL12.INST1\Database_Growth_Watchdog.xel', | |
| max_file_size = ( 10 ) ) | |
| WITH ( MAX_MEMORY = 4096 KB, | |
| EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS, |
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
| -- returns all members | |
| exec xp_logininfo 'DOMAIN\Group Name', 'members' | |
| -- return login info | |
| exec xp_logininfo 'Domain\Group Name' |
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
| USE master; | |
| DECLARE @killSessions varchar(8000) = ''; | |
| SELECT @killSessions = @killSessions + 'kill ' + CONVERT(varchar(5), spid) + ';' | |
| FROM master..sysprocesses | |
| WHERE dbid = db_id('dbname') | |
| EXEC(@killSessions); | |
| ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE; | |
| GO |
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
| --temp tables using up space | |
| USE <database_name> | |
| SELECT tb.name AS [Temporary table name], | |
| stt.row_count AS [Number of rows], | |
| stt.used_page_count * 8 AS [Used space (KB)], | |
| stt.reserved_page_count * 8 AS [Reserved space (KB)] FROM tempdb.sys.partitions AS prt | |
| INNER JOIN tempdb.sys.dm_db_partition_stats AS stt | |
| ON prt.partition_id = stt.partition_id | |
| AND prt.partition_number = stt.partition_number |