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

Tag: Data Integrity

AI

The AI Prompt That Checks Your Soft-Delete Queries for a Forgotten WHERE Clause That Lets Deleted Rows Leak Back Into a Report

- 05.11.26 - ErcanOPAK comment on The AI Prompt That Checks Your Soft-Delete Queries for a Forgotten WHERE Clause That Lets Deleted Rows Leak Back Into a Report

🤖 The AI Prompt That Checks Your Soft-Delete Queries for a Forgotten WHERE Clause That Lets Deleted Rows Leak Back Into a Report A soft-delete pattern (a deleted_at timestamp or an is_deleted flag instead of an actual row removal) only works if every single read path across the codebase remembers to filter it out, and […]

Read More
SQL

SQL Server: Fix a Foreign Key Constraint Allowing an Update That Should Have Failed Because It Was Created With NOCHECK and Never Revalidated

- 31.10.26 - ErcanOPAK comment on SQL Server: Fix a Foreign Key Constraint Allowing an Update That Should Have Failed Because It Was Created With NOCHECK and Never Revalidated

🗄️ Fix a Foreign Key Constraint Allowing an Update That Should Have Failed Because It Was Created With NOCHECK and Never Revalidated Adding a foreign key constraint to a table that already has rows in it with WITH NOCHECK is a common move when the existing data is known to already have some violations that […]

Read More
SQL

SQL Server: Fix a Trigger Silently Not Firing on a Bulk Insert Because the Bulk Copy Operation Was Run With FIRE_TRIGGERS Left Off

- 30.10.26 - ErcanOPAK comment on SQL Server: Fix a Trigger Silently Not Firing on a Bulk Insert Because the Bulk Copy Operation Was Run With FIRE_TRIGGERS Left Off

🗄️ Fix a Trigger Silently Not Firing on a Bulk Insert Because the Bulk Copy Operation Was Run With FIRE_TRIGGERS Left Off `BULK INSERT`, `bcp`, and `SqlBulkCopy` from application code are all built to load large volumes of data with as little per-row overhead as possible — and part of that design is that none […]

Read More
SQL

SQL Server: Fix an UPDATE … FROM Statement That Silently Updates From a Different Join Row Than Expected Because the Join Isn’t Unique

- 23.10.26 - ErcanOPAK comment on SQL Server: Fix an UPDATE … FROM Statement That Silently Updates From a Different Join Row Than Expected Because the Join Isn’t Unique

🗄️ Fix an UPDATE … FROM Statement That Silently Updates From a Different Join Row Than Expected Because the Join Isn’t Unique An UPDATE statement joined to another table to pull in a value – a current price, a latest status – assumes there’s exactly one matching row on the other side of the join […]

Read More
AI

The AI Prompt That Reviews Your Code for a Bulk Delete or Update Running Without a Transaction, Leaving Data Half-Changed on Failure

- 23.10.26 - ErcanOPAK comment on The AI Prompt That Reviews Your Code for a Bulk Delete or Update Running Without a Transaction, Leaving Data Half-Changed on Failure

🤖 The AI Prompt That Reviews Your Code for a Bulk Delete or Update Running Without a Transaction, Leaving Data Half-Changed on Failure A bulk operation – deleting every row matching a filter, updating a batch of records, cascading a change across a few related tables – that isn’t wrapped in a transaction looks completely […]

Read More
SQL

SQL Server: Fix String Data Getting Silently Truncated Instead of Erroring Because SET ANSI_WARNINGS Was OFF for That Session

- 22.10.26 - ErcanOPAK comment on SQL Server: Fix String Data Getting Silently Truncated Instead of Erroring Because SET ANSI_WARNINGS Was OFF for That Session

🗄️ The INSERT That Should Have Failed but Didn’t With ANSI_WARNINGS ON (the default for most client connections, including SSMS), inserting or updating a string value that’s too long for its target column’s declared length raises a hard error – ‘String or binary data would be truncated’ – and rejects the statement outright, but with […]

Read More
SQL

SQL Server: Fix Optimistic Concurrency Checks That Silently Always Succeed Because a rowversion Column Was Never Compared in the WHERE Clause

- 16.10.26 - ErcanOPAK comment on SQL Server: Fix Optimistic Concurrency Checks That Silently Always Succeed Because a rowversion Column Was Never Compared in the WHERE Clause

🗄️ The Optimistic Lock That Never Actually Checked Anything A rowversion (timestamp) column is the standard way SQL Server supports optimistic concurrency: you read a row along with its rowversion, and when you save, your UPDATE’s WHERE clause includes that original rowversion value – if someone else changed the row in between, the WHERE clause […]

Read More
SQL

SQL Server: Fix a CHECK Constraint That Silently Lets NULL Bypass the Rule It Was Meant to Enforce

- 15.10.26 - ErcanOPAK comment on SQL Server: Fix a CHECK Constraint That Silently Lets NULL Bypass the Rule It Was Meant to Enforce

🗄️ The Constraint That Let Nothing Through A CHECK constraint only rejects rows where its expression evaluates to definitely FALSE – and SQL’s three-valued logic treats any comparison involving NULL as UNKNOWN, not FALSE. A constraint written as CHECK (Price > 0) rejects a negative price correctly, because that comparison is definitely false, but it […]

Read More
SQL

SQL Server: Fix ON DELETE CASCADE Silently Deleting Rows Several Tables Away Through a Chain of Foreign Keys You Forgot About

- 15.10.26 - ErcanOPAK comment on SQL Server: Fix ON DELETE CASCADE Silently Deleting Rows Several Tables Away Through a Chain of Foreign Keys You Forgot About

🗄️ The Delete That Took Three Tables Down With It ON DELETE CASCADE on a foreign key doesn’t stop at the next table – if that child table is itself the parent of another cascading foreign key, deleting the original row triggers a chain reaction straight down through every table that transitively points back at […]

Read More
SQL

SQL Server: Fix a CHECK Constraint That Silently Stops Enforcing New Violations After a Bulk Load Leaves It Marked NOT TRUSTED

- 10.10.26 - ErcanOPAK comment on SQL Server: Fix a CHECK Constraint That Silently Stops Enforcing New Violations After a Bulk Load Leaves It Marked NOT TRUSTED

🗄️ The Constraint That Stopped Checking Loading data with WITH CHECK CONSTRAINTS temporarily disabled, or re-enabling a constraint afterward with the default WITH NOCHECK, re-activates that constraint for all future inserts and updates but leaves it marked as NOT TRUSTED – a state where SQL Server has deliberately decided not to verify whether the existing […]

Read More
SQL

SQL Server: Fix a Recursive CTE That Runs Forever Because the Anchor and Recursive Parts Never Agree on a Stop Condition

- 04.10.26 - ErcanOPAK comment on SQL Server: Fix a Recursive CTE That Runs Forever Because the Anchor and Recursive Parts Never Agree on a Stop Condition

🗄️ The Recursive Query That Never Agreed On When to Stop A recursive common table expression has two halves that have to cooperate to actually terminate – the anchor member seeds the first set of rows, and the recursive member joins back to the expression’s own name to produce the next set, repeating until a […]

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 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: 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 NOLOCK Silently Returns Duplicate or Missing Rows

- 30.08.26 | 31.08.26 - ErcanOPAK comment on SQL Server: Why NOLOCK Silently Returns Duplicate or Missing Rows

🗄️ NOLOCK = Maybe-Correct Results WITH (NOLOCK) is everywhere as a quick fix for blocking, but it doesn’t just risk reading uncommitted data — under real concurrent writes it can return the SAME row twice or skip a row entirely, with no error to tell you it happened. 🐞 The Problem SELECT OrderId, CustomerName, Total […]

Read More
C#

C#: Why DateTime.Now Is Silently Corrupting Your Data Across Time Zones

- 30.08.26 - ErcanOPAK comment on C#: Why DateTime.Now Is Silently Corrupting Your Data Across Time Zones

🔧 DateTime.Now = Timezone Time Bomb Your app works perfectly in testing, then a customer in another time zone reports appointments showing up on the wrong day, or scheduled jobs running an hour early or late after a daylight-saving change. The root cause is almost always DateTime.Now. 🐞 The Problem public class Appointment { public […]

Read More
SQL

SQL: The ‘IsDeleted’ Pattern vs Data Integrity

- 28.02.26 - ErcanOPAK comment on SQL: The ‘IsDeleted’ Pattern vs Data Integrity

Never physically DELETE data in enterprise apps. Use a bit column IsDeleted. But how do you handle unique constraints? Pro Tip: Use a Filtered Unique Index. This allows you to have the same email address in a ‘Users’ table if the previous ones are marked as deleted. CREATE UNIQUE INDEX UI_ActiveEmail ON Users(Email) WHERE IsDeleted […]

Read More
SQL

SQL: Professional Soft Delete Strategy for Data Safety

- 21.02.26 - ErcanOPAK comment on SQL: Professional Soft Delete Strategy for Data Safety

Never DELETE from production. Use an IsDeleted bit column and a Global Query Filter to hide deleted data while keeping it recoverable.

Read More
SQL

SQL: Use Computed Columns for Automatic Calculated Values

- 21.02.26 - ErcanOPAK comment on SQL: Use Computed Columns for Automatic Calculated Values

Calculating values in application code requires logic duplication. Computed columns calculate automatically in database. Create Computed Column: CREATE TABLE Orders ( OrderId INT PRIMARY KEY, Quantity INT, PricePerUnit DECIMAL(10,2), — Computed column (calculated automatically) TotalPrice AS (Quantity * PricePerUnit), — Persisted (stored, can be indexed) TotalWithTax AS (Quantity * PricePerUnit * 1.1) PERSISTED ); Automatic […]

Read More
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,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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