EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Data Science Data Science Tutorials SQL Tutorial SQL Case Insensitive

SQL Case Insensitive

Payal Udhani
Article byPayal Udhani
Priya Pedamkar
Reviewed byPriya Pedamkar

Updated March 10, 2023

SQL Case Insensitive

Introduction to SQL Case Insensitive

SQL Case insensitivity is to use the query statements and the keywords tables and columns by specifying them in capital or small letters of alphabets. SQL keywords are by default set to case insensitive that means that the keywords are allowed to be used in lower or upper case. The names of the tables and columns specification are set to case insensitive on the SQL database server, however, it can be enabled and disabled by configuring the settings in SQL. The COLLATION is the property that decides and helps us to specify whether the elements other than keywords in SQL are to be allowed for case insensitivity or not. In this article, we will learn how we can define case sensitivity with the collation and check for the assigned collation values and supported collation values by your SQL database server.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Checking the Case-Sensitivity of SQL Server

We can write the keywords SELECT, FROM, WHERE, GROUP BY, etc. in either upper or lower case as they are case insensitive in SQL. The objects other than the keywords like names of columns, tables, views, triggers, stored procedures, etc. can either be case sensitive or case insensitive. By default, they are set to case insensitive. The COLLATION property of the SQL server can be checked by using the function named Serverproperty() of SQL and passing the COLLARION as the parameter to it to get the value that is set as the collation to that SQL server. After executing it, you will get the collation value as shown in the output of the following query statement most of the times –

SELECT Serverproperty('COLLATION') AS COLLATION;

The output of the execution of the above query statement is as follows:

SQL Case Insensitive-1.1

The collation value contains either CI or CS in it. They stand for case insensitive and case sensitive respectively. In the above output, we can observe that collation value contains CI that is case sensitive, and hence while querying on that database server the objects other than keywords can be specified in upper or lower case. The same applies to keywords as they are allowed to be entered in any case but most of the time it is a good practice to use them in all upper cases according to conventions.

Alternatively, the collation property for SQL database server can also be checked by querying on the table named databases that are present in sys database of your SQL server to check for the case sensitivity that is allowed for the particular database by mentioning the value of the name column as the value of your database name for which you are checking the collation. Let us a query for the existing database at my SQL server named educba and check for the collation value using the contents of the databases named table of sys database and following query statement –

SELECT collation_name AS COLLATION
FROM sys.databases
WHERE name = 'educba';

The output of the execution of the above query statement is a follows giving the collation value as SQL_Latin1_General_CP1_CI_AS in which CI stands for case insensitivity which allows us to query on that database by specifying non-keyword words in upper or lower case –

SQL Case Insensitive-1.2

The collation property can also be assigned on specific tables and columns of it to override the default collation property. The collation on the table can simply be checked by altering it using the F6 key in SQLyog or by querying on it using SELECT NAME, collation_name FROM sys.databases. Consider an existing table named educba_articles n my educba database in SQL. When checked its collation is set to value latin1_swedish_ci which is again allowance of case insensitive usage of non-keyword objects.

SQL Case Insensitive-1.3

  • Checking collation of columns of the table

The collation can be overridden further from database server level to database level and then to table level and lastly to the column level. The hierarchy is defined in the above sentence. Suppose that now we want to check the collation property of the columns of the table educba_articles that exists in my SQL database. We can do that by simply executing the following query statement –

SELECT
COLUMN_NAME,
COLLATION_NAME
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'educba_articles'
AND CHARACTER_SET_NAME IS NOT NULL ;

The output of the execution of the above query statement is follows –

SQL Case Insensitive-1.4

We can check the allowed collation values for our SQL database server by querying on the fn_helpcollations() of sys database and retrieving the name of the collation and its description using the following query statement –

SELECT name, description FROM sys.fn_helpcollations();

The output of the execution of the above query statement is follows –

SQL Case Insensitive-1.5

  • Using LOWER( ad UPPER() functions for case sensitive queries

Suppose that the table named educba_articles that exists in my educba database has the collation set to case sensitive collation as shown in the below image –

Output-1.6

Let us check the contents of the table by executing the following query statement on the table –

SELECT * FROM educba_articles;

The output of the execution of the above query statement is follows –

Output-1.7

Now, executing the following query using lower function helps in retrieving all the submitted records –

SELECT * FROM educba_articles WHERE LOWER(status) = "submitted";

The output of the execution of the above query statement is follows –

Output-1.8

Now, we will use the function to make an insensitive comparison that makes the comparison using the UPPER function as shown in the below query statement –

SELECT * FROM educba_articles WHERE UPPER(status) = "SUBMITTED";

The output of the execution of the above query statement is follows –

Output-1.9

In the similar fashion UPPER() and LOWER() functions can be used in the LIKE clause for getting similar records and making the search insensitive in the table or database having collation that shows CS that is case sensitive in its collation.

Conclusion

The SQL case sensitivity can be set for non-keyword objects such as tables and columns by specifying the collation against the database, tables, and column level by mentioning CI or CS in it that stands for case insensitive and case sensitive respectively.

Recommended Articles

We hope that this EDUCBA information on “SQL Case Insensitive” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. SQL Select Top
  2. SQL DROP TRIGGER
  3. MySQL Show Users
  4. MySQL Cross Join
ADVERTISEMENT
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW