Skip to content

Instantly share code, notes, and snippets.

@chadbaldwin
chadbaldwin / New Index TX Log Impact Testing.sql
Created March 26, 2025 21:25
New Index TX Log Impact Testing
------------------------------------------------------------
GO
------------------------------------------------------------
SELECT [CurrentDB] = (SELECT x.recovery_model_desc FROM sys.databases x WHERE [name] = DB_NAME())
------------------------------------------------------------------------------
GO
------------------------------------------------------------------------------
IF OBJECT_ID('tempdb..#tmp_log_track','U') IS NOT NULL DROP TABLE #tmp_log_track; --SELECT * FROM #tmp_log_track
CREATE TABLE #tmp_log_track (
ID int NOT NULL IDENTITY(1,1),
@chadbaldwin
chadbaldwin / TableSize.sql
Last active October 13, 2024 07:40
DBADash - Improve performance of TableSize report
------------------------------------------------------------------------------
GO
------------------------------------------------------------------------------
DROP VIEW IF EXISTS dbo.vw_TableSize_Snapshots;
GO
CREATE OR ALTER VIEW dbo.vw_TableSize_Snapshots
WITH SCHEMABINDING
AS
SELECT InstanceID, DatabaseID, SnapshotDate, ObjectCount = COUNT_BIG(*)
FROM dbo.TableSize
@chadbaldwin
chadbaldwin / feedback test results.md
Last active August 23, 2024 22:00
SQL Feedback: Odd (and inconsistent) behaviour with datetime/datetime2 comparisons
@chadbaldwin
chadbaldwin / gist:a6f17da40d6696a4febb9c3de3fb521f
Last active February 5, 2024 21:46
SQL Server Suggestions
Add some sort of "reset_time" or similar to Index stats DMVs
https://feedback.azure.com/d365community/idea/e9e84bf2-64c4-ee11-92bc-000d3a0fb290
Output warning message when altering an indexed view that all indexes (clustered and non-clustered will be dropped)
https://feedback.azure.com/d365community/idea/0f1f2993-43b6-ee11-92bc-000d3a033659
Statement execution duration global variable - Similar to @@ROWCOUNT, but instead how long the previous statement took to run
https://feedback.azure.com/d365community/idea/884c86b1-9b85-ee11-a81c-000d3ae5ae95
# Run this script from within the git repo you want to copy data OUT of
$copyTo = 'C:\MyTestFolder'
$ErrorActionPreference = 'Stop'
$currBranch = git branch --show-current
$repoRoot = git rev-parse --show-toplevel
if ($LASTEXITCODE -gt 0) { return }
@chadbaldwin
chadbaldwin / string_agg_bug.sql
Created November 13, 2023 22:17
SQL Server STRING_AGG bug
SELECT TOP(100) t.[name], c.TestA, c.TestB
FROM sys.tables t
CROSS APPLY (
SELECT TestA = STRING_AGG(c.[name], '_')
, TestB = STRING_AGG(c.[name], ',')
FROM sys.columns c
WHERE c.[object_id] = t.[object_id]
) c
WHERE t.is_ms_shipped = 1
ORDER BY t.[object_id]
@chadbaldwin
chadbaldwin / Start SQL Server Container.ps1
Last active April 21, 2025 22:12
Using Docker, create a SQL Server container, or start one of it already exists.
<# Docs:
https://hub.docker.com/_/microsoft-mssql-server
https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables
#>
# Start SQL Server docker instance
Write-Verbose 'Creating function: Start-SQLServer'
function Start-SQLServer {
[CmdletBinding()]
param (
@chadbaldwin
chadbaldwin / auto entities card + restriction card + template card.md
Last active September 1, 2023 00:54
auto entities card + restriction card + template card

.