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

CRUD Operations

CRUD stands for Create, Read, Update and Delete. These are the four basic operations performed on data stored in a database.

Almost every database-driven application uses CRUD operations. In a Student Management System, for example, we can create a student record, read student information, update student details and delete a student record.

What is CRUD?

CRUD is a commonly used term in software development for describing the four fundamental operations performed on persistent data.

Operation Meaning Purpose Common SQL Command
Create Add new data Creates a new record. INSERT
Read Retrieve data Reads existing records. SELECT
Update Modify data Changes an existing record. UPDATE
Delete Remove data Deletes an existing record. DELETE

CRUD Operations Flow

The four CRUD operations can be understood using the following flow:

CRUD

                    CRUD
                      |
        --------------------------------
        |              |              |
      CREATE          READ          UPDATE
        |              |              |
      INSERT         SELECT         UPDATE
        |
        -------------------------------
                      |
                    DELETE
                      |
                    DELETE
            

1. Create

The Create operation is used to add new records to a database table.

In SQL Server, the INSERT statement is commonly used to perform the Create operation.

SQL
INSERT INTO Students
(
    StudentId,
    StudentName,
    Age
)
VALUES
(
    101,
    'Rahul',
    22
);

2. Read

The Read operation is used to retrieve existing data from a database table.

In SQL Server, the SELECT statement is used to read data.

SQL
SELECT *
FROM Students;

3. Update

The Update operation is used to modify existing data in a database table.

In SQL Server, the UPDATE statement is used to modify existing records.

SQL
UPDATE Students
SET Age = 23
WHERE StudentId = 101;

4. Delete

The Delete operation is used to remove existing records from a database table.

In SQL Server, the DELETE statement is commonly used for this operation.

SQL
DELETE FROM Students
WHERE StudentId = 101;

CRUD in Student Management System

Let's understand CRUD using a Student Management System.

Requirement CRUD Operation SQL Command
Add a new student Create INSERT
Display student details Read SELECT
Change student details Update UPDATE
Remove a student Delete DELETE

CRUD Lifecycle

CRUD

User
  |
  ↓
Create Data
  |
  ↓
Database
  |
  ↓
Read Data
  |
  ↓
Update Data
  |
  ↓
Delete Data
            

CRUD and SQL Commands

CRUD SQL Command Action
Create INSERT Add record
Read SELECT Retrieve record
Update UPDATE Modify record
Delete DELETE Remove record
Important

CRUD operations form the foundation of database-driven applications. In real-world applications, these operations are usually performed through application interfaces such as web pages, APIs or backend services.

Summary

CRUD stands for Create, Read, Update and Delete. Create uses INSERT to add data, Read uses SELECT to retrieve data, Update uses UPDATE to modify data and Delete uses DELETE to remove data. These four operations are fundamental to most database-driven applications.