Debugging a Complex T-SQL Issue

  Рет қаралды 3,341

Brent Ozar Unlimited

Brent Ozar Unlimited

Күн бұрын

Ever wonder how someone else does it? Watch as Brent Ozar debugs a query error that seems simple on the surface, gets progressively harder to nail down, and then finally solves it.

Пікірлер: 15
@superbaran9042
@superbaran9042 Күн бұрын
This is what I'm watching during my an hour long work meeting....
@aler.4108
@aler.4108 Күн бұрын
Right choice, bro ;)
@VladDBA
@VladDBA Күн бұрын
It's so awesome that you've recorded this! I kept coming back to the issue trying to reproduce it with different instance configurations, but still no go.
@mattcargile
@mattcargile Күн бұрын
Holy smokes! An hour of Brent O!🎉
@Leggolem_
@Leggolem_ Күн бұрын
I’m over here screaming in my head watching this but only half way through. I know exactly why this is happening, because I ran into something like this recently. Hoping you figure it out before then end, if not, I’ll make sure to share the solution and reason. Excited to see you work through this! Edit: Yay! You got it fixed. Check reply for details on why I think this is happening.
@Leggolem_
@Leggolem_ Күн бұрын
Here’s why this is happening. Inside a stored procedure, things run within the context of the database the stored procedure is in, not the database you are calling from. So when the stored procedure has SELECT * FROM dbo.Log, you can be sure it will select from the Log table in the same database as the stored procedure. Think about how messed up things could get if this didn’t happen! How could you ever be sure your stored procedure will run as you intended? You can’t control what database people call your procedure from. Now things get complicated with the execution of dynamic sql. Looks like that happens in the context of the database you are calling from, instead of the stored procedures’s database. This is super important to know! If you depend on dynamic SQL running within the context of your stored procedure’s database, you may need to prefix the sp_executesql with your stored procedure’s database name. I’d have to think out how to work around that in this situation. Your solution seems to be a good one here. Anyway, figured I would share the main reason. Hope it helps!
@Leggolem_
@Leggolem_ Күн бұрын
I wonder if sp_executesql would be any different than EXEC() inside a stored procedure. Do both use the caller’s db? Does one use the stored procedure’s db? I’ll have to test this later to put my mind at ease, lol. Gotta solve the mystery!
@Leggolem_
@Leggolem_ Күн бұрын
Thinking about this more, if sp_executesql runs within the context of the caller’s db, then you might not even need to prefix the callers db into your synonym. Just running it inside the dynamic SQL might be enough. I’ll have to test this too!
@romeo2473
@romeo2473 18 сағат бұрын
I have no idea what you guys are doing here, but I'm just commenting my way through. Don't mind me, carry on. Dog bless
@eustacelufgren
@eustacelufgren 11 сағат бұрын
Last 12 years I've been at a place with (mostly) binary collation and the case sensitivity issues with Deadlock and DeadLock keeps jumping out at me (granted, most people aren't in binary collation)
@joshash5944
@joshash5944 22 сағат бұрын
dynamic sql... synonyms... what could go wrong😃
@scbtripwire
@scbtripwire 5 сағат бұрын
I'm here because of the division by zero in the thumbnail's SQL. Wtf.
@wfvdijk1
@wfvdijk1 20 сағат бұрын
to proof: use master go create procedure sp_testme as begin select * from sys.tables; end; go use sandbox -- change me go create table doesitshowup(id int); go exec sp_testme go
@CaribouDataScience
@CaribouDataScience Күн бұрын
Just ask ChatGPT 😮
@chebrubin
@chebrubin Күн бұрын
Don't they have a CoPilot plugin for MS SQL Server Studio 2025?
Office Hours: The Warlock of Databases
15:10
Brent Ozar Unlimited
Рет қаралды 1,6 М.
Epic Reflex Game vs MrBeast Crew 🙈😱
00:32
Celine Dept
Рет қаралды 28 МЛН
Un coup venu de l’espace 😂😂😂
00:19
Nicocapone
Рет қаралды 9 МЛН
Errichto Stream, POI 22/1
3:55:08
Errichto Algorithms
Рет қаралды 160 М.
SQLite: How it works, by Richard Hipp
1:39:27
Prof. Dr. Jens Dittrich, Big Data Analytics
Рет қаралды 10 М.
Office Hours: Back at Home (Briefly)
13:27
Brent Ozar Unlimited
Рет қаралды 1,4 М.
Expert Level SQL Tutorial
23:27
James Oliver
Рет қаралды 155 М.
Kubernetes 101 workshop - complete hands-on
3:56:03
Kubesimplify
Рет қаралды 1,6 МЛН
Что лучше ноутбук или ПК в бюджете 100к?
0:34
Cómo pensaba que sería el iPhone 16 😭
0:12
Alan
Рет қаралды 2,6 МЛН
iPad Domino has been in use for a long time. Let's see the effect
0:12
3D Fantasy Life
Рет қаралды 718 М.
How to connect electrical wires with good contact #short
0:29
Tuan CT
Рет қаралды 22 МЛН