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 @schema varchar(MAX); | |
EXEC master.dbo.sp_WhoIsActive @get_locks = 1, @find_block_leaders = 1, @get_plans = 1, @output_column_list = ' | |
[dd hh:mm:ss.mss][sql_text][query_plan][locks][blocking_session_id][blocked_session_count][wait_info] | |
[CPU][used_memory][reads][writes][physical_reads] | |
[status][open_tran_count][percent_complete] | |
[host_name] | |
[database_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
DECLARE @StartTime datetime = GETDATE(); | |
DECLARE @LastMinuteStart datetime = DATEADD(MINUTE, -1, @StartTime); | |
DECLARE @CurrentMinuteStart datetime; | |
DECLARE @CurrentMinuteStartMessage nvarchar(30); | |
DECLARE @LastRowCount bigint = -1; | |
WHILE 1 = 1 | |
BEGIN | |
SET @CurrentMinuteStart = DATEADD(MINUTE, DATEDIFF(MINUTE, @StartTime, GETDATE()), @StartTime); |
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 @JobName sysname = '[SQL-SERVER-AGENT-JOB-NAME]'; /* Enter the job name you want to view the job history for */ | |
DECLARE @DaysBack int = 5; /* Change this value as needed */ | |
DECLARE @ShowOnlyJobSummary bit = 1; /* Set to 1 for just the summary, or 0 for all job steps */ | |
DECLARE @ShowJobInformation bit = 0; /* Set to 1 to view the job information. You can also view this in SSMS under SQL Server Agent -> Jobs */ | |
/********************************************************************************************************************** | |
** Job History | |
**********************************************************************************************************************/ | |
SET NOCOUNT ON; |
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
/********************************************************************************************************************** | |
** Name: SQL Server Database and Object ANSI Settings Check | |
** Description: Validates that database-level ANSI settings, object-level metadata (ANSI_NULLS, QUOTED_IDENTIFIER), | |
** DDL SET options, and column-level ANSI_PADDING are correctly configured to ensure compatibility with | |
** indexed views, filtered indexes, persisted computed columns, and standards-based T-SQL behavior. | |
** | |
** NOTE: MANUAL CHECK REQUIRED FOR TABLES | |
** Tables do not store ANSI_NULLS or QUOTED_IDENTIFIER settings in metadata. These settings are | |
** session-level at creation and cannot be altered later. | |
** To check: |
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
/********************************************************************************************************************** | |
** Nullable Columns with No Non-Null Rows Check | |
** Use to find nullable columns with no non-null rows. | |
** For more information see: https://www.spdevelop.org/best-practices-and-findings/table-conventions#150 | |
** Can be intensive if no supporting indexes, so run outside of work hours. | |
**********************************************************************************************************************/ | |
DECLARE @SchemaName sysname = NULL; /* Set to NULL to process all schemas. */ | |
DECLARE @TableName sysname = NULL; /* Set to NULL to process all tables. */ | |
/* End configurable variables */ |
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 @TableName sysname = '<SchemaName, , dbo>.<TableName, , MyTable>'; | |
SET NOCOUNT ON; | |
DECLARE | |
@column_id varchar(36) | |
,@StringToExecute nvarchar(MAX); | |
DROP TABLE IF EXISTS #Receiver; | |
CREATE TABLE #Receiver (LongestDataLength int NULL); |
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
Remove-Module SqlServer | |
Import-Module SqlServer -RequiredVersion 22.3.0 -Force | |
$ServerInstance = "SQLServerName" | |
$Database = "DatabaseName" | |
$Path = "C:\Export\" | |
$TableListQuery = "SELECT | |
SchemaTableName = S.name + '.' + T.name | |
,SchemaTableNameCleaned = REPLACE(S.name, '\', '') + '.' + REPLACE(T.name, '\', '') | |
FROM |
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
SET NOCOUNT ON; | |
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; | |
WITH TableInformation | |
AS ( | |
SELECT | |
object_id = T.object_id | |
,[Schema Name] = S.name | |
,[Table Name] = T.name | |
,[Table Description] = CONVERT(nvarchar(MAX), EP.value) | |
FROM |
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
/************************************************************************************************* | |
** # Database User and Roles Assignment Script | |
** | |
** If your application uses only one database, a contained user should be created (RECOMMENDED) | |
** You can create a contained user in each database with the same username and password | |
** If your application uses multiple databases, you CAN create a SQL Server login (NOT RECOMMENDED) | |
** You will create a database user from the SQL Server login for each database | |
** THIS IS NOT PORTABLE! SQL LOGIN MUST BE CREATED ON OTHER SQL SERVERS WITH THE SAME SID. | |
** | |
** This script will enabled contained users if it is executed on a SQL Server |
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
/** | |
Summary: > | |
This is a temporary batch for creating such things as table variables, | |
temporary tables or anything else that needs a column list | |
Author: Phil Factor | |
Based on code from https://www.red-gate.com/hub/product-learning/sql-prompt/building-reusable-table-build-scripts-using-sql-prompt | |
**/ | |
Declare @TheExpression NVARCHAR(MAX)= | |
N'$SELECTEDTEXT$' |
NewerOlder