Skip to content

Conversation

@MisterZeus
Copy link
Contributor

When you run sp_BlitzIndex on a database/schema/table that actually has a name of nvarchar(128),
it blows up at the debug step "Inserting data into #ForeignKeys".

I found this was because one of the @Dsql values was being truncated when you pass a database name of 128 chars.

The easiest fix was to edit the offending @Dsql query to stop using millions of consecutive spaces, and swap instead to tabs and well-formatted code.

You can replicate the problem and test the fix by creating The Horrible Database, Schema, and Table below, and running sp_BlitzIndex in various @modes.
(the names contain 128 Unicode characters, including some Greek at the start, and a space, to really test your code properly!)

CREATE DATABASE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF] ON PRIMARY (
NAME = N'DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
LOG ON (
NAME = N'LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,FILENAME = N'C:\SQL\LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
,SIZE = 1MB
,MAXSIZE = 20MB
,FILEGROWTH = 10MB
)
;
USE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE SCHEMA [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE TABLE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
.[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
(
[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
[tinyint] NOT NULL
)

…r(128)

When you run sp_BlitzIndex on a database/schema/table that actually has a name of nvarchar(128), it blows up at the debug step "Inserting data into #ForeignKeys".

You can replicate this by creating The Horrible Database, Schema, and Table below:

CREATE DATABASE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
ON PRIMARY (
	 NAME            = N'DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
	,FILENAME = N'C:\SQL\DATA456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
	,SIZE = 1MB
	,MAXSIZE = 20MB
	,FILEGROWTH = 10MB
	)
LOG ON (
	 NAME            = N'LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
	,FILENAME = N'C:\SQL\LOG3456789ABCDEFΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
	,SIZE = 1MB
	,MAXSIZE = 20MB
	,FILEGROWTH = 10MB
	)
;
USE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE SCHEMA [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
GO
CREATE TABLE [ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
            .[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
	(
	[ΑβΓδε 6789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
	[tinyint] NOT NULL
	)
Copy link
Member

@BrentOzar BrentOzar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get your changes down to just what matters? I'm trying to review the code and it looks like there are tons of changes - you can see it here: https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/pull/3738/files?diff=split&w=1

I'm guessing you ran this code through some kind of formatter, and just at a glance, I'm not sure what changes you're making on purpose versus on accident. Thanks for understanding!

@MisterZeus
Copy link
Contributor Author

@BrentOzar should be cleaner now? Just removing whitespace to make the string smaller so it stops truncating the end of the dynamic tsql.

Copy link
Member

@BrentOzar BrentOzar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do me a favor - when you submit a pull request, look at the file diff in Github, look to see if the changes are actually what you want. Right now, the only change is just spacing and casing. I don't think this is really what you want.

@BrentOzar
Copy link
Member

Here's what your diff looks like - just spacing and casing changed:
Screenshot 2025-11-17 at 6 19 48 PM

Let's start this from scratch and do it the right way - create an issue with the problem you're describing, and let's go from there. Thanks!

@BrentOzar BrentOzar closed this Nov 18, 2025
@MisterZeus MisterZeus deleted the MisterZeus-patch-1 branch November 18, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants