SQL Server Collation – Specify Different Collation for Data vs Entities

case sensitivecollationsql serversql-server-2016

I have a database with a case sensitive collation because the data inside of it should be treated as case sensitive in the context of how it's used.

The entities and their column names within that same database don't need to be case sensitive and we'd prefer that they weren't for querying purposes.

Is it possible to keep the data itself as case sensitive but allow the entities to be case insensitive within the same database?

Best Answer

Yes. Turn on partial database containment, and you’ll get a case-insensitive catalog collation along with the collation of your choice for the data.

In a contained database, the catalog collation Latin1_General_100_CI_AS_WS_KS_SC. This collation is the same for all contained databases on all instances of SQL Server and cannot be changed. The database collation is retained, but is only used as the default collation for user data. By default, the database collation is equal to the model database collation, but can be changed by the user through a CREATE or ALTER DATABASE command as with non-contained databases.

See https://docs.microsoft.com/en-us/sql/relational-databases/databases/contained-database-collations?view=sql-server-ver15

And note that Azure SQL Database always uses contained database collations.