Why is my SQL Server Query Case Sensitive?

I am trying to run Queries in MS SQL Server  and it comes up with errors if I specify table names or column names in a different case. The query is case-sensitive….!!!! I thought SQL queries are not case-sensitive.  i.e MyTableName and mytablename means the same.                                                                             

 

Yes, SQL queries can be case-sensitive or case-insensitive, but it all depends on the Collation you have selected for the Database.

 

If you have selected the collation Latin1_General_CI_AS it will be case-insensitive

And if you have selected  Latin1_General_CS_AS it will be case-sensitive

 

How would you change the collation for your database?

Its pretty simple.

 

1.       Goto  SQL Server Management Studio

2.       Right click on the Database you want to change and select Properties

3.       Select Options in the Database Properties Window 

4.  On the Right Pane of the Window you should see the Collation with a drop – down with a list of collations available. Select a Case Sensitive One or a Case Insensitive one as required.  (The one with CI are case-insensitive and the ones with CS are case-sensitive)