How to change SQL Server to be case sensitive

The default COLLATE in SQL Server is “Latin1_GENERAL_CI_AS”, which means it’s Case Insensitive and Accent Sensitive. There are cases that you want to be case sensitive while doing a join, compare a value etc. There two ways to accomplish it.

  • ALTER DATABASE database_name COLLATE Latin1_GENERAL_CS_AS
    It will change the whole db to this collate. Need to back the db and all that.
  • AA left join BB on AA.Fobkey = BB.Fobkey COLLATE Latin1_GENERAL_CS_AS
    The collate only apply to this operation. There are cases that you have no control of the collate of the whole database, then it’s the only option you have.