DBMS Lab ASS#2
DBMS Lab ASS#2
By
AQIB RAZA
CIIT/FA19-BCS-126/ATK
Teacher: Mr. WASEEM KHAN
Submission Date: Monday, March 8, 2021
Let us understand the IN, Between and Like operators with examples. We are going to use the
following Employee_5 tables to understand these special operators.
SQL Script to create database EmployeeData_1, Employee_5 table and populate Employee_5
table with test data.
BETWEEN Operator in SQL Server:
The BETWEEN operator in SQL Server is used to get the values within a range. Generally, we use
the BETWEEN operator in WHERE clause to get values within a specified range. For example, if
you want to fetch all the employees between id 3 and 7 from the Employee_5 table, then you
need to use the BETWEEN operator.
The above SQL statement will return records from the Employee_5 table where the
employee_5 id is between 3 and 7. Following is the output of the above SQL query.
IN Operator in SQL Server:
The IN Operator in SQL Server is used to search for specified values matches any value in the set
of multiple values it accepts. Generally, we will use this IN operator in WHERE clause to
compare column or variable values with a set of multiple values. For example, if you want to
fetch all the employees whose department is either IT or HR, then you could write the SQL
Query using the IN Operator as shown below.
This is one of the most frequently used operators in SQL Server. The LIKE operator in SQL Server
is used to search for character string with the specified pattern using wildcards in the column.
In SQL Server, pattern means its specific string of characters with wildcards to search for
matched expressions. Generally, we will use this LIKE operator in WHERE clause. Here, we will
try to understand the LIKE operator using different types of wildcard characters.
Example2:
The following SQL query will return all employees whose CITY ends with the character ‘k’. This is
because here we mentioned the pattern as ‘%a’. This means return all records whose name
ends with the character ‘a’.
Example3:
The following SQL query will return all employees with CITY containing the word ‘am’ anywhere
in the name column because we mentioned patterns like ‘%am%’. This means it will check for
the respective word anywhere in column irrespective of characters in front or back.