Sunday, April 4, 2021

 

Case Sensitive Search using SQL

   Part - 29


Link for video answer:



--********************************************************************************
-- Q29 -- Case Sensitive Search using SQL
--********************************************************************************

This can be achieved by changing the collation settings. If you set this at database level, this would be impacted by all the tables under that table. However you can use this with in Select statement with COLLATE so that it can to a Case sensitive Search.

If you want to see the current collation, use below query:







-- SQL_Latin1_General_CP1_CI_AS -- Case Insensitivity
--Latin1_General_CS_AS -- Case Sensitivity

Lets Illustrate with an example:

CREATE TABLE EmployeeName (EmpName Nvarchar(50))

INSERT EmployeeName VALUES ('Microsoft'), ('MicroSoft'), ('MICROSOFT'),('microsoft')

SELECT * FROM EmployeeName








This query returns all rows irrespective of the case sensitivity. We can use COLLATE to force use the Case Sensitivity or we can set at database level as well based on the requirement.


 







Using Collate, It retrieves only one record.

Thank you!. If you like this video, pls subscribe to my channel and like the video

No comments:

Post a Comment

  Printing Number Pattern using SQL Link for video answer: SQL: --********************* --PRINT Pattern --********************* -- 1 -- ...