Implicit conversions
We introduced the concept of implicit conversions in the chapter Exploring Query Execution Plans, particularly in the context of PlanAffectingConvert
warnings. An implicit conversion happens when the SQL Database Engine needs to compare two values that are not of the same data type. At this point we should understand how to recognize an implicit conversion in our query plans, but what may not always be obvious is how they got there in the first place and how to correct them.
The most obvious cause of implicit conversions is to compare two columns that are not of the same data type. We can easily avoid this by making sure that columns that are related in our database, and thus may be joined, are of the same data type. A common mistake that can cause this situation is where we have some tables that have been created with NVARCHAR
strings and some tables that have VARCHAR
strings. This may happen because a database was upgraded at some point to support Unicode...