Master SQL Server From Scratch

Clear, interactive, and structured SQL Server lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to SQL Server
Introduction to SQL Server SQL Server Installation SQL Server Fundamentals
2. Data Types
Data Types Numeric Data Types Character & String Data Types Date & Time Data Types Other SQL Server Data Types
3. Database & Tables
Database & Tables Introduction Creating a Database Creating Tables Table Structure Altering Tables Dropping Tables
4. Constraints
Constraints Introduction PRIMARY KEY FOREIGN KEY UNIQUE Constraint NOT NULL & DEFAULT CHECK Constraint
5. SQL Basics
SQL Basics Introduction SQL Commands SQL Command Categories SELECT Statement INSERT, UPDATE & DELETE
6. CRUD Operations
CRUD Operations Introduction INSERT Operation SELECT Operation UPDATE Operation DELETE Operation
7. SQL Queries
Queries Introduction WHERE Clause ORDER BY Clause DISTINCT LIKE Operator IN, BETWEEN & IS NULL
8. Joins
Joins Introduction INNER JOIN LEFT JOIN RIGHT JOIN FULL OUTER JOIN CROSS JOIN
9. SQL Functions
SQL Functions Introduction String Functions Numeric Functions Date & Time Functions Conversion Functions NULL Functions
10. Grouping & Aggregate Functions
GROUP BY Aggregate Functions COUNT() SUM() AVG() MIN() & MAX()
11. Subqueries
Subqueries Introduction Single-Row Subquery Multiple-Row Subquery Correlated Subquery Subquery with DML
12. Views
SQL Views Introduction Creating a View Updating a View Altering a View Dropping a View
13. Stored Procedures
Stored Procedures Introduction Creating a Stored Procedure Input Parameters Output Parameters Executing & Modifying Stored Procedures
14. Triggers
Triggers Introduction AFTER INSERT Trigger AFTER UPDATE Trigger AFTER DELETE Trigger INSTEAD OF Trigger
15. Transactions
Transactions Introduction COMMIT ROLLBACK SAVEPOINT Transaction with TRY...CATCH
16. Indexes
Indexes Introduction Clustered Index Non-Clustered Index Creating & Dropping Indexes Index Performance
17. Common Table Expressions
CTE Introduction Simple CTE CTE with JOIN CTE with Aggregate Functions Recursive CTE
18. Window Functions
Window Functions Introduction ROW_NUMBER() RANK() and DENSE_RANK() LEAD() and LAG() PARTITION BY
19. Advanced SQL
Advanced SQL Introduction Temporary Tables Table Variables Dynamic SQL Error Handling Performance Optimization

LIKE Operator

The LIKE operator is used to search for a specified pattern in a column.

It is mainly used when we do not know the complete value and want to find records based on a particular pattern.

What is LIKE Operator?

The LIKE operator is used with the WHERE clause to search for a specific pattern in character or string data.

LIKE is commonly used for searching names, cities, email addresses and other text values.

Syntax

SQL
SELECT column_name
FROM table_name
WHERE column_name LIKE 'pattern';

Example Table

StudentId StudentName City Course
101 Rahul Pune .NET
102 Priya Mumbai Java
103 Amit Nashik Python
104 Neha Pune .NET
105 Rohan Pune Java

% Wildcard

The % wildcard represents zero, one or multiple characters.

Starts With a Pattern

To find names that start with a particular character, place the character before the % wildcard.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE 'R%';

This returns students whose names start with R.

Ends With a Pattern

To find names ending with a particular character, place the % wildcard before the character.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE '%a';

This searches for names ending with the letter a.

Contains a Pattern

To search for a character or pattern anywhere in the value, use % on both sides.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE '%an%';

This searches for names containing the pattern an.

_ Underscore Wildcard

The underscore _ wildcard represents exactly one character.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE 'R_hul';

Here, the underscore represents one character between R and hul.

Multiple Underscores

Multiple underscore characters can be used when a fixed number of unknown characters are required.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE '____';

This pattern matches values containing exactly four characters.

LIKE with WHERE

LIKE is normally used together with the WHERE clause.

SQL
SELECT StudentName, City
FROM Students
WHERE City LIKE 'P%';

This searches for cities beginning with the letter P.

LIKE with AND

Multiple LIKE conditions can be combined using AND.

SQL
SELECT *
FROM Students
WHERE StudentName LIKE 'R%'
AND City LIKE 'P%';

This searches for students whose name starts with R and whose city starts with P.

LIKE with OR

SQL
SELECT *
FROM Students
WHERE City LIKE 'P%'
OR City LIKE 'M%';

This searches for cities beginning with either P or M.

NOT LIKE

The NOT LIKE operator is used when we want values that do not match a specified pattern.

SQL
SELECT *
FROM Students
WHERE StudentName NOT LIKE 'R%';

This returns students whose names do not start with R.

Important

  • LIKE is used for pattern matching.
  • % represents zero or more characters.
  • _ represents exactly one character.
  • LIKE is commonly used with WHERE.
  • NOT LIKE is used to exclude a matching pattern.

Summary

In this section, we learned how the LIKE operator is used for pattern matching in SQL Server. We covered the % and _ wildcards, starts-with, ends-with, contains, NOT LIKE, and combining LIKE with AND and OR.