If the collation is set to CI containing the value that is Case insensitive, then there is no necessity to use any function like LOWER() or UPPER() to make the search to ignore the case. 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. For this, our query statement will be as follows – SELECT * FROM educba_articles WHERE UPPER(` name`) LIKE "%ING%" Now, let us use the upper() function to use the search facility that makes the ignore-case search. Our query statement is as follows – SELECT * FROM educba_articles WHERE LOWER(` name`) LIKE "%ing%" We can use the LIKE clause for searching the contents containing the “ing” value in the name, and further to search such that the case is ignored, we will use the LOWER() function first. Consider that we have to find out all the records of the table educba_articles table “ing” value in its name column. In a similar fashion, UPPER() and LOWER() functions can be used in the LIKE clause for getting similar records and making the search ignoring the case in the table or database having collation that shows CS that is case sensitive in its collation. 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" Now, executing the following query using lower function helps in retrieving all the submitted records – SELECT * FROM educba_articles WHERE LOWER(status) = "submitted" Let us check the contents of the table by executing the following query statement on the table – SELECT * FROM educba_articles 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 – Using LOWER() and UPPER() functions for case in-sensitive that is ignoring the case in queries. 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 – 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 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.Īlternatively, the collation property for SQL database server can also be checked by querying on the table named databases that are present in the 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. In the above output, we can observe that the 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. They stand for case insensitive and case sensitive, respectively. The collation value contains either CI or CS in it. The output of the execution of the above query statement is as follows – SELECT Serverproperty('COLLATION') AS COLLATION In this topic, we are going to learn about SQL ignore-case. In this article, we will learn how we can check for the assigned collation values that determine case sensitivity of SQL and further see how lower and upper functions are used to make the queries that ignore the case of the values of the columns while searching or applying restriction. 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. 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. SQL keywords are by default set to case insensitive, which means that the keywords are allowed to be used in lower or upper case. SQL Case sensitivity is to use the query statements and the keywords tables and columns by specifying them in capital or small letters of alphabets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |