Suppose a column contains CaseSearch, casesearch, CASESEARCH, and CaSeSeArCh. A user wants just the lowercase value. This is the small interview example I originally used, and it is clearer than starting with a tour of every SQL Server collation option.

Question: How do you make one SQL Server text search case sensitive?
Answer: Apply a case-sensitive collation to the comparison. First check the actual column collation, because a database or server default may differ from the column. Run the self-contained four-value example in a fresh query window without an existing #CaseSearch table:
CREATE TABLE #CaseSearch
(
Column1 nvarchar(40) COLLATE Latin1_General_100_CI_AS NOT NULL
);
INSERT #CaseSearch (Column1) VALUES
(N'CaseSearch'), (N'casesearch'),
(N'CASESEARCH'), (N'CaSeSeArCh');
SELECT Column1
FROM #CaseSearch
WHERE Column1 = N'casesearch';
SELECT Column1
FROM #CaseSearch
WHERE Column1 COLLATE Latin1_General_100_CS_AS = N'casesearch';
The declared CI collation makes the first comparison case insensitive, so all four values qualify. The CS comparison distinguishes the capitalization and returns the lowercase value. This is the same idea as the original Latin1_General_CS_AS example, with an explicit case-insensitive starting column so the demonstration behaves consistently on different servers.
Collation also controls more than case. Accent behavior is a separate choice, and a binary collation answers a different matching question. Do not change a whole database default to solve one exceptional query. If this search becomes common and the column is indexed under a different collation, test the plan and consider a schema design that supports both the required comparison and an efficient access path.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.
Discover more from SQL Authority with Pinal Dave
Subscribe to get the latest posts sent to your email.





3 Comments. Leave new
Sir is there any process by using which we can make our whole database case sensitive or insensitive ? Does CS and IS stands for case sensitive and case insensitive ?
Hi Manish,
As mentioned above sql server has default case insensitive collation. you can set collation as per your requirement at time of installation or you can alter it. see below links for ref.
http://blog.sqlauthority.com/2007/04/30/case-sensitive-sql-query-search/
https://docs.microsoft.com/en-us/sql/relational-databases/collations/set-or-change-the-database-collation?view=sql-server-2017
hope this helps :)
I’m curious about something after reading this blog, and yes, I will try to set up a test later on….
First, if you need to use a collation in a WHERE clause of an indexed column, to get either the case-insensitive or case-sensitive results desired, are you guaranteeing a index scan versus a seek?
I’ve read where it is not good to have different collations for tempdb versus a database (or column in a database). I assume this is true. So, I’m wondering if one can create a computed column, with the desired (different) collation, add a similar index, and presumably regain the performance that might otherwise be lost.