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 Basics Introduction

SQL, which stands for Structured Query Language, is used to communicate with relational databases. SQL Server uses SQL commands to create, retrieve, modify and manage data stored in databases.

What is SQL?

SQL is a standard language used to work with relational databases. It allows developers and database administrators to perform operations such as creating databases, creating tables, inserting records, retrieving data, updating records and deleting records.

Simple Definition

SQL is a language used to communicate with and manage data in a relational database.

Why Do We Use SQL?

SQL provides commands that allow us to work with the data stored inside database tables.

  • Create databases and tables
  • Insert new records
  • Retrieve data
  • Update existing records
  • Delete records
  • Filter and sort data
  • Manage database objects

SQL and SQL Server

SQL is the language used to communicate with a relational database. SQL Server is a relational database management system developed by Microsoft that understands and executes SQL statements.

SQL Server

                                                        Application
                                                             ↓
                                                          SQL Query
                                                              ↓
                                                          SQL Server
                                                             ↓
                                                        Database Engine
                                                             ↓
                                                          Database
                                                             ↓
                                                           Result

First SQL Query

A simple SELECT statement can be used to retrieve data from a table.

SQL
SELECT *
FROM Students;

The above query retrieves all columns and all records from the Students table.

Example

Suppose the Students table contains the following records:

StudentId StudentName Age
101 Rahul 22
102 Priya 21
103 Amit 23
SQL
SELECT StudentName, Age
FROM Students;
Output
StudentName Age
Rahul 22
Priya 21
Amit 23

Basic SQL Statement Structure

Most SQL statements follow a specific structure depending on the operation being performed.

SQL
SELECT column_name
FROM table_name;
Keyword Purpose
SELECT Specifies the columns to retrieve.
FROM Specifies the table from which data is retrieved.

Basic SQL Operations

SQL provides different commands for performing common database operations.

Operation SQL Command Purpose
Create CREATE Create database objects.
Retrieve SELECT Retrieve data.
Insert INSERT Add new records.
Update UPDATE Modify existing records.
Delete DELETE Remove records.

How a SQL Query Works

When a SQL query is executed, SQL Server processes the statement and returns the requested result.

SQL Server
User
  ↓
SQL Statement
  ↓
SQL Server
  ↓
Database Engine
  ↓
Table / Data
  ↓
Result

Simple SQL Examples

SQL
-- Retrieve data
SELECT * FROM Students;

-- Insert data
INSERT INTO Students
VALUES (104, 'Neha', 22);

-- Update data
UPDATE Students
SET Age = 23
WHERE StudentId = 104;

-- Delete data
DELETE FROM Students
WHERE StudentId = 104;
Important

SQL statements should always be written carefully, especially UPDATE and DELETE statements. A missing WHERE condition can affect multiple records.

Summary

In this section, we learned what SQL is, why SQL is used, how SQL communicates with SQL Server, the basic structure of SQL statements and the common operations used to work with database data.