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

SQL Queries

SQL Queries are used to retrieve, filter, sort and manipulate data stored in SQL Server databases.

In this module, we will learn commonly used SQL queries and clauses that help us work efficiently with database data.

What is a SQL Query?

A SQL query is a statement written using Structured Query Language (SQL) to communicate with a database.

Using SQL queries, we can retrieve data, filter records, sort results, group data and perform calculations.

Basic SQL Query

SQL
SELECT *
FROM Students;

This query retrieves all columns and all records from the Students table.

Common SQL Query Clauses

Clause Purpose
SELECT Retrieves data from a table.
FROM Specifies the table from which data is retrieved.
WHERE Filters records based on a condition.
ORDER BY Sorts the query result.
GROUP BY Groups rows having similar values.
HAVING Filters grouped results.

Example – WHERE Clause

SQL
SELECT *
FROM Students
WHERE Age > 21;

This query returns only those students whose age is greater than 21.

Example – ORDER BY

SQL
SELECT *
FROM Students
ORDER BY StudentName ASC;

This query sorts the student records by StudentName in ascending order.

How a SQL Query Works

  1. The query is written using SQL syntax.
  2. SQL Server parses and validates the query.
  3. SQL Server determines how to execute the query.
  4. The requested result is returned to the user.

Important Points

  • SQL queries are used to communicate with databases.
  • SELECT is commonly used to retrieve data.
  • WHERE is used to filter records.
  • ORDER BY is used to sort results.
  • GROUP BY is used to group records.
  • HAVING is used to filter grouped results.

Summary

In this section, we introduced SQL Queries and learned the purpose of commonly used clauses such as SELECT, FROM, WHERE, ORDER BY, GROUP BY and HAVING.