Skip to content
Home » TSQL

TSQL

Understanding ‘ALTER TABLE SWITCH statement failed’ errors 4907, 4908, and 4912

Recently we’ve encountered an interesting use case for a customer.

They had a table with partitioning that they needed to be archived (with the help of said partitioning), but the ALTER TABLE SWITCH commands were failing with a peculiar error:

Error 4907, ‘ALTER TABLE SWITCH’ statement failed. The table ‘MyDB.dbo.PrtTable1’ has 4 partitions while index ‘IX1’ has 6 partitions.

This prompted some insightful research into some of the validations done by SQL Server behind the scenes when executing an ALTER TABLE SWITCH command.

Read More »Understanding ‘ALTER TABLE SWITCH statement failed’ errors 4907, 4908, and 4912

Solving the Latch Convoy Problem with OPTIMIZE_FOR_SEQUENTIAL_KEY in SQL Server 2019

Have you ever come across an elusive SQL Server issue known as the “Latch Convoy Problem” or “Last Page Insert Contention”? It’s a rare and challenging problem to encounter in real-world scenarios. In fact, it’s so uncommon that many database professionals may go their entire careers without experiencing it firsthand. But sometimes, the unexpected happens, and you find yourself face to face with this elusive beast.

Resolved: Login failed for user NT AUTHORITY\ANONYMOUS LOGON – Delegation Step-by-Step

Sometimes when trying to access a linked server, you’d get an error saying “Login failed for user NT AUTHORITY\ANONYMOUS LOGON”. This happens because you’re connected using Windows authentication, and SQL Server fails to “forward” your credentials to the linked server.

Hopefully, with this blog post, I’ll provide you with an easy-to-understand step-by-step guide, which would help you resolve the issue the right way, without any workarounds.

Read More »Resolved: Login failed for user NT AUTHORITY\ANONYMOUS LOGON – Delegation Step-by-Step

Could SQL Injection be dangerous even when perfectly safe?

SQL Injection is something I would expect any reader of my blog to be familiar with. Despite being one of the oldest database attack methods, it still persists for decades on the OWASP Top Ten list of critical security risks to web applications.

In fact, instead of dying out, it only seems to be getting more clever and even automated. With “hacker bots” scouring the web and automatically probing for injection vulnerabilities to exploit. I know, as I’ve once been a victim of such attacks in the past.

But today I’m not actually going to talk about that. Today, I’m going to ask the question: When is SQL Injection dangerous, even if it’s perfectly safe?

Read More »Could SQL Injection be dangerous even when perfectly safe?

T-SQL Tuesday #152 – Which version of my database was deployed? It depends!

This month’s T-SQL Tuesday is hosted by Deb the DBA (b|t), who invites us to give a long rant about a question that a coworker could be asking us, without knowing what they’ve just gotten themselves into by doing that.

Well… I’ve got just the thing 🤭

Read More »T-SQL Tuesday #152 – Which version of my database was deployed? It depends!