Saturday, 9 December 2017

Case Sensitive and Case InSensitive in SQL Server.

In this article, We will discuss about Case Sensitive and Case InSensitive in SQL Server.

By default, SQL Server is Case InSensitive.

Case Sensitive or Case Insensitive applies to Database,Tables and Columns Only.

Whenever we will Create a new database,tables and Columns by default it Will take as a Case InSensitive.

Case Sensitive also applies to those Columns Whose datatype is char,varchar, nvarchar and text because in these datatype both Small case and Capital case are different in terms of ASCII code.

For Example,  "A" and "a" both are different because "A" letter ascii code is 65 and "a" letter ascii code is 97.

So, due to ascii code We can apply case sensitive to char,varchar,nvarchar and text datatype. 

In the below example, I Showed How Case Insensitive by default applies to a particular varchar Column.


Here in the above image i created one table Whose name is LoginDet with 2 Columns as IID and VarPwd. In the VarPwd Column you can see by default it will take "SQL_Latin1_General_CP1_CI_AS" Collation.

If We want then at the time of table Creation also We can Create Column as Case Sensitive by applying "SQL_Latin1_General_CP1_CS_AS" Collation.

Collation means nothing about Particular rules and here Case Sensitive and Case InSensitive are two Collation.

Case Sensitive =  "SQL_Latin1_General_CP1_CS_AS" Collation
Case InSensitive = "SQL_Latin1_General_CP1_CI_AS" Collation

Below is an example of How to change one column from Case Insensitive to Case Sensitive to an existing Column.

Example:-
-------------

alter table LoginDet 
alter column VarPwd varchar(10) Collate SQL_Latin1_General_CP1_CS_AS

So after this Column Changed, the Case Sensitive looks like as follows,


Even if  We can add Case Sensitive and Case Insensitive While Creating the table.

0 comments:

Post a Comment