Skip to content

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
SQL

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

- 06.09.26 - ErcanOPAK

๐Ÿ—„๏ธ 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, but because a view’s column list gets bound at CREATE time, and unless it’s refreshed, it can end up silently reading MORE data than the query actually needs.

๐Ÿ”Ž The Problem

CREATE VIEW ActiveCustomers AS
SELECT * FROM Customers WHERE IsActive = 1;

-- Months later, someone adds a large NVARCHAR(MAX) "Notes" column to
-- Customers for an unrelated feature. The view'"'"'s metadata (sys.columns
-- for the view) still reflects the OLD column list from creation time
-- until it'"'"'s refreshed - meaning queries against the view can behave
-- inconsistently with the current table shape, and once refreshed,
-- SELECT * now pulls that large new column into every query that uses
-- the view, even ones that never needed it.

โœ… Fix: Avoid SELECT * in Views, and Refresh Metadata When Schema Changes

  • Rewrite the view with an explicit column list – `SELECT CustomerId, Name, Email FROM Customers WHERE IsActive = 1` – so adding unrelated columns to the base table never changes what the view returns or how much data it reads.
  • After any base table schema change, run `EXEC sp_refreshview ‘ActiveCustomers’` to force the view’s cached metadata to match the table’s current definition – `SELECT *`-based views in particular can behave unpredictably with stale metadata until this is done.

โš ๏ธ Why This Is Easy to Miss

  • The person who added the new column to `Customers` often has no reason to think about `ActiveCustomers` at all – the view’s slowdown is a side effect of a change made somewhere else entirely, which is exactly what makes it hard to connect during troubleshooting.
  • Explicit column lists in views are one of those practices that cost nothing when a view is created but save real debugging time months later, precisely because they decouple the view’s behavior from whatever unrelated changes happen to the base table.

A view built on SELECT * isn’t a fixed shape – it’s a promise to reflect whatever the table looks like later, and that promise isn’t always the one you meant to make.

โ€” Database Engineer

Related posts:

SQL Window Functions โ€” The Fastest Way to Do Ranking & Aggregates

How to get the first and the last day of previous month in SQL Server

SQL Performance Drops After Adding โ€œHelpfulโ€ Indexes

Post Views: 1

Post navigation

Photoshop: Recover an Action That Stops Partway Through a Batch Run
WordPress: Recover Custom Code a Theme Update Removed From functions.php

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

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

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (951)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

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