Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: SQL

SQL

SQL Server: Why a Table Variable Gets a Far Worse Execution Plan Than the Same Query With a Temp Table

- 03.10.26 - ErcanOPAK comment on SQL Server: Why a Table Variable Gets a Far Worse Execution Plan Than the Same Query With a Temp Table

🔧 The Table Variable the Optimizer Refused to Study A table variable and a temp table can hold identical rows and support nearly identical syntax, but the query optimizer treats them very differently: a temp table gets real statistics, the same way a permanent table does, while a table variable gets none at all. Whatever […]

Read More
SQL

SQL Server: Why Using a Scalar Function Inside a SELECT List Silently Kills Query Parallelism

- 03.10.26 - ErcanOPAK comment on SQL Server: Why Using a Scalar Function Inside a SELECT List Silently Kills Query Parallelism

🔧 The One Scalar Function That Kept the Whole Query on a Single Thread A scalar user-defined function called inside a SELECT list looks like it should only cost whatever that function costs per row, but SQL Server’s restriction goes further than that: a scalar UDF forces the entire statement that calls it onto a […]

Read More
SQL

SQL Server: Why a Query Using TOP Without ORDER BY Returns Different Rows Each Time You Run It

- 03.10.26 - ErcanOPAK comment on SQL Server: Why a Query Using TOP Without ORDER BY Returns Different Rows Each Time You Run It

🔧 The TOP 10 That Wasn’t the Same Top 10 Twice SELECT TOP 10 reads as though it should reliably return some specific, repeatable set of ten rows – and for a while, against a small, rarely-changed table, it usually does, purely by accident of how the data happens to be laid out on disk. […]

Read More
SQL

SQL Server: Fix a Query That Returns Different Row Counts Depending on the Session’s Isolation Level

- 03.10.26 - ErcanOPAK comment on SQL Server: Fix a Query That Returns Different Row Counts Depending on the Session’s Isolation Level

🔧 The Row Count That Changed Depending on Who Was Asking Running what looks like the exact same SELECT statement from two different connections, or from the same report run twice a few seconds apart, and getting two different row counts back feels like data corruption or a flaky query – but it’s frequently just […]

Read More
SQL

SQL Server: Fix a Query Slowdown That Only Appears After the Table Crosses a Row-Count Threshold

- 27.09.26 - ErcanOPAK comment on SQL Server: Fix a Query Slowdown That Only Appears After the Table Crosses a Row-Count Threshold

🗄️ The Query That Ran Fine for Months and Then Suddenly Didn’t A query that performs well for a long time and then degrades sharply, with no code change involved at all, is very often explained by the query optimizer switching strategies once a table’s row count crosses an internal threshold – a plan that […]

Read More
SQL

SQL Server: Why Two Sessions Can See Different Data Inside What Looks Like the Same Transaction

- 27.09.26 - ErcanOPAK comment on SQL Server: Why Two Sessions Can See Different Data Inside What Looks Like the Same Transaction

🗄️ The Two Sessions That Disagreed About What the Database Actually Said Two connections querying the exact same table at nearly the same moment can legitimately see different data – not due to a bug in either query, but because the database’s isolation level governs exactly what a transaction is allowed to see of another […]

Read More
SQL

SQL Server: Why Rebuilding a Clustered Index Doesn’t Fix Fragmented Non-Clustered Indexes

- 27.09.26 - ErcanOPAK comment on SQL Server: Why Rebuilding a Clustered Index Doesn’t Fix Fragmented Non-Clustered Indexes

🗄️ The Index Maintenance Job That Fixed Half the Problem Rebuilding a table’s clustered index is often assumed to clean up fragmentation across the whole table, since the clustered index IS the table’s physical data. But every non-clustered index stores its own separate copy of the columns it covers, plus the clustering key as its […]

Read More
SQL

SQL Server: Fix a Blocking Chain That Isn’t a Deadlock and Never Resolves on Its Own

- 27.09.26 - ErcanOPAK comment on SQL Server: Fix a Blocking Chain That Isn’t a Deadlock and Never Resolves on Its Own

🗄️ The ‘Deadlock’ That SQL Server Never Once Detected A long chain of sessions blocking each other (A waits on B, B waits on C, C waits on D) is often assumed to be a deadlock, but SQL Server’s deadlock detector only fires when there’s an actual CYCLE – some session in the chain waiting, […]

Read More
SQL

SQL Server: Why a Unique Constraint Still Allows Two ‘Duplicate’ Rows When One Column Is NULL

- 27.09.26 - ErcanOPAK comment on SQL Server: Why a Unique Constraint Still Allows Two ‘Duplicate’ Rows When One Column Is NULL

🗄️ The Unique Constraint That Let Two Identical Rows Through Anyway A unique constraint on a column is expected to guarantee no two rows ever share the same value – but SQL Server (following the ANSI SQL standard) treats NULL as never equal to anything, including another NULL, so a unique constraint on a nullable […]

Read More
SQL

SQL Server: Fix a Logon Trigger That Silently Blocks Every New Connection After a Typo

- 27.09.26 - ErcanOPAK comment on SQL Server: Fix a Logon Trigger That Silently Blocks Every New Connection After a Typo

🗄️ One Small Typo in a Logon Trigger, and Suddenly Nobody Can Connect A server-level logon trigger (used for auditing connections, enforcing connection policies, or restricting login times) runs on EVERY login attempt to the server – so a bug introduced in the trigger’s own code doesn’t just fail quietly, it can block every single […]

Read More
SQL

SQL Server: Why a Temp Table Inside a Stored Procedure Triggers Constant Recompilation

- 26.09.26 - ErcanOPAK comment on SQL Server: Why a Temp Table Inside a Stored Procedure Triggers Constant Recompilation

🗄️ The Stored Procedure That Recompiles Itself Almost Every Time It Runs A stored procedure that creates a `#temp` table, inserts a meaningful number of rows into it, and then queries it can trigger SQL Server’s automatic recompilation logic FAR more often than expected – because a significant enough change in a temp table’s row […]

Read More
SQL

SQL Server: Fix a MERGE Statement That Inserts Duplicate Rows Instead of Updating Them

- 26.09.26 - ErcanOPAK comment on SQL Server: Fix a MERGE Statement That Inserts Duplicate Rows Instead of Updating Them

🗄️ MERGE Was Supposed to Update, and It Inserted a Duplicate Instead A `MERGE` statement written to “update if it exists, insert if it doesn’t” can end up inserting duplicate rows for keys that genuinely already exist – not because `MERGE` itself is buggy, but because the join condition used to match source and target […]

Read More
SQL

SQL Server: Why a Full-Text Search Misses Rows That Clearly Contain the Word You Searched For

- 26.09.26 - ErcanOPAK comment on SQL Server: Why a Full-Text Search Misses Rows That Clearly Contain the Word You Searched For

🗄️ The Word Is Right There, and the Search Still Says No Matches A `CONTAINS()` or `FREETEXT()` full-text query returning zero rows for a word you can literally see in the data isn’t usually a bug in SQL Server – it’s almost always the full-text index being stale, a word breaker/stoplist treating the term differently […]

Read More
SQL

SQL Server: Fix a Login That Works Fine in SSMS but Fails Every Time From the Application

- 26.09.26 - ErcanOPAK comment on SQL Server: Fix a Login That Works Fine in SSMS but Fails Every Time From the Application

🗄️ The Same Login, Two Completely Different Outcomes A SQL login that connects instantly in SSMS and fails every single time from the application is rarely a password problem – it’s almost always a difference in HOW the two clients connect: a different authentication mode, a different default database, or a connection string missing a […]

Read More
SQL

SQL Server: Fix a Transaction That Holds Locks Much Longer Than It Should

- 26.09.26 - ErcanOPAK comment on SQL Server: Fix a Transaction That Holds Locks Much Longer Than It Should

🗄️ Your Transaction Is Holding Locks Far Longer Than the Actual Database Work Requires A transaction wraps a database update and holds row/table locks for the ENTIRE duration it’s open – and if application code does something slow INSIDE that open transaction (an external API call, a large in-memory computation, waiting on user input), every […]

Read More
SQL

SQL Server: Why Identical Queries Get Two Different Execution Plans

- 26.09.26 - ErcanOPAK comment on SQL Server: Why Identical Queries Get Two Different Execution Plans

🗄️ The Exact Same Query Gets Two Completely Different Execution Plans Two calls to what looks like the identical query – same SQL text, same table – produce two different execution plans and wildly different performance, and the usual cause is PARAMETER SNIFFING’S sibling problem: statistics that were stale or a plan that was cached […]

Read More
SQL

SQL Server: Fix a Column Default Value That Doesn’t Apply to Rows Inserted by the App

- 06.09.26 - ErcanOPAK comment on SQL Server: Fix a Column Default Value That Doesn’t Apply to Rows Inserted by the App

🗄️ Your Column Has a Default Value – and the App’s Inserted Rows Don’t Get It A column is given a `DEFAULT` constraint specifically so new rows automatically get a sensible value without every INSERT having to specify it – and rows inserted by the application keep showing NULL (or 0) instead, because a column […]

Read More
SQL

SQL Server: Why NULL Values Break a Simple NOT IN Subquery

- 06.09.26 - ErcanOPAK comment on SQL Server: Why NULL Values Break a Simple NOT IN Subquery

🗄️ Your NOT IN Subquery Returns Nothing at All – Because of One NULL Value A `NOT IN` subquery that should exclude a handful of specific IDs instead returns ZERO rows entirely, not just the wrong rows – and the cause is almost always a single NULL value hiding in the subquery’s result set, because […]

Read More
SQL

SQL Server: Fix a Foreign Key Constraint That Silently Allows Orphaned Rows

- 06.09.26 - ErcanOPAK comment on SQL Server: Fix a Foreign Key Constraint That Silently Allows Orphaned Rows

🗄️ Your Foreign Key Is Defined – and Orphaned Rows Are Getting Through Anyway A foreign key constraint exists on a table specifically to prevent rows that reference a parent that doesn’t exist – and yet orphaned rows keep showing up, almost always because the constraint was created with `WITH NOCHECK` or later disabled and […]

Read More
SQL

SQL Server: Why a View Gets Slower After Adding a Column to Its Base Table

- 06.09.26 - ErcanOPAK comment on SQL Server: Why a View Gets Slower After Adding a Column to Its Base Table

🗄️ Your View Got Slower the Day You Added One Column to Its Base Table A view built with `SELECT *` (or one that references a table’s columns without an explicit list) runs noticeably slower after an unrelated new column is added to the underlying table – not because the new column is expensive to […]

Read More
SQL

SQL Server: Fix a Deadlock That Only Happens During the Nightly Batch Job

- 06.09.26 - ErcanOPAK comment on SQL Server: Fix a Deadlock That Only Happens During the Nightly Batch Job

🗄️ The Deadlock That Only Ever Happens During the Nightly Batch Job Two processes never deadlock during the day, only overnight when the batch job runs – because the batch job touches the same tables the live application does, but in a different order, and it’s exactly the mismatched ORDER of lock acquisition between the […]

Read More
SQL

SQL Server: Why an Index Seek Turns Into a Scan After a Parameter Type Mismatch

- 06.09.26 - ErcanOPAK comment on SQL Server: Why an Index Seek Turns Into a Scan After a Parameter Type Mismatch

🗄️ Your Index Seek Turned Into a Scan the Day the Parameter Type Stopped Matching A query that used to seek cleanly on an indexed column suddenly scans the entire table instead – not because the index disappeared, but because the parameter being passed in has a different data type than the column, forcing SQL […]

Read More
SQL

SQL Server: Fix a Query Plan That Changes for the Worse After Updating Statistics

- 05.09.26 - ErcanOPAK comment on SQL Server: Fix a Query Plan That Changes for the Worse After Updating Statistics

🗄️ You Updated Statistics to Help the Optimizer – It Made a Worse Choice Instead Updating statistics is standard, recommended maintenance meant to help SQL Server’s query optimizer make better decisions – and right after running it, a previously fast query suddenly gets a noticeably worse execution plan, the opposite of what updating statistics is […]

Read More
SQL

SQL Server: Why a Computed Column Can’t Be Indexed Until You Mark It PERSISTED

- 05.09.26 - ErcanOPAK comment on SQL Server: Why a Computed Column Can’t Be Indexed Until You Mark It PERSISTED

🗄️ You Added an Index on the Computed Column – SQL Server Refuses It A computed column built from a simple expression looks like any other column and should, in theory, be indexable like one – and creating an index on it fails outright with an error about the column not being deterministic or precise […]

Read More
SQL

SQL Server: Why COUNT(*) and COUNT(column) Can Return Different Numbers

- 05.09.26 - ErcanOPAK comment on SQL Server: Why COUNT(*) and COUNT(column) Can Return Different Numbers

🗄️ Two COUNT Queries on the Same Table – Two Different Numbers COUNT(*) on a table returns one number, and COUNT(SomeColumn) on the exact same table, in the exact same query otherwise, returns a smaller one – not a bug, but a distinction that trips up anyone who assumed the two were interchangeable ways of […]

Read More
SQL

SQL Server: Fix a Trigger That Fires Multiple Times for a Single Multi-Row Update

- 05.09.26 - ErcanOPAK comment on SQL Server: Fix a Trigger That Fires Multiple Times for a Single Multi-Row Update

🗄️ Update 500 Rows at Once – Your Trigger Assumed It’d Only Ever Get One A trigger written and tested against single-row updates works perfectly for months, until a batch process updates 500 rows in one statement – and the trigger’s logic, which quietly assumed exactly one affected row, either processes only one of them […]

Read More
SQL

SQL Server: Fix a Query That Times Out Only When Run Through a Linked Server

- 05.09.26 - ErcanOPAK comment on SQL Server: Fix a Query That Times Out Only When Run Through a Linked Server

🗄️ Run It Locally: Instant. Run It Through the Linked Server: Times Out. The exact same query, run directly against its own database, returns in under a second. Run through a linked server from another instance – a common pattern for cross-database reporting – and it times out entirely, even though the underlying data and […]

Read More
SQL

SQL Server: Why TRUNCATE TABLE Fails on an Empty Table With a Foreign Key

- 05.09.26 - ErcanOPAK comment on SQL Server: Why TRUNCATE TABLE Fails on an Empty Table With a Foreign Key

🗄️ The Table Is Completely Empty – TRUNCATE Still Refuses You go to clear out a table that has zero rows in it, expecting TRUNCATE TABLE to be instant and harmless on an already-empty table – and SQL Server refuses outright with a foreign key error, even though there’s nothing in the table for a […]

Read More
SQL

SQL Server: Fix a Stored Procedure That Runs Fast Alone but Slow When Called From the App

- 31.08.26 - ErcanOPAK comment on SQL Server: Fix a Stored Procedure That Runs Fast Alone but Slow When Called From the App

🗄️ Run It in SSMS: Instant. Call It From the App: Ten Seconds. The exact same stored procedure, with what looks like the exact same parameters, runs instantly when you execute it directly in SQL Server Management Studio – and takes ten seconds every time the application calls it. Nothing about the query changed between […]

Read More
SQL

SQL Server: Recover Data From a Corrupted Database Using DBCC CHECKDB Before You Panic

- 31.08.26 - ErcanOPAK comment on SQL Server: Recover Data From a Corrupted Database Using DBCC CHECKDB Before You Panic

🗄️ Before You Restore From Backup, Run This One Command A query suddenly throws a corruption error – torn page, checksum mismatch – and the instinct is to panic and start restoring from last night’s backup immediately, losing a full day of transactions. There’s a faster, less destructive first step almost everyone skips. 🐞 The […]

Read More
Page 5 of 17
« Previous 1 2 3 4 5 6 7 8 9 10 … 17 Next »

Posts pagination

« Previous 1 … 3 4 5 6 7 … 17 Next »
November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (577)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • Ağ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com