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 Commands

SQL commands are instructions used to communicate with a database. They allow us to create database objects, retrieve data, insert new records, modify existing records and remove records.

What are SQL Commands?

SQL commands are statements written using SQL syntax. These statements are executed by SQL Server to perform a specific operation on a database or its data.

Simple Definition

SQL commands are instructions used to perform operations on databases and database objects.

Common SQL Commands

Command Purpose Example
CREATE Creates database objects. CREATE TABLE
SELECT Retrieves data. SELECT * FROM Students
INSERT Adds new records. INSERT INTO Students
UPDATE Modifies existing records. UPDATE Students
DELETE Removes records. DELETE FROM Students
ALTER Changes the structure of an object. ALTER TABLE
DROP Removes a database object. DROP TABLE

CREATE Command

The CREATE command is used to create database objects such as databases and tables.

SQL
CREATE TABLE Students
(
    StudentId INT,
    StudentName VARCHAR(100),
    Age INT
);

SELECT Command

The SELECT command is used to retrieve data from one or more tables.

SQL
SELECT *
FROM Students;

INSERT Command

The INSERT command is used to add new records to a table.

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

UPDATE Command

The UPDATE command is used to modify existing records in a table.

SQL
UPDATE Students
SET Age = 23
WHERE StudentId = 101;
Important: Always use a WHERE condition carefully with UPDATE to avoid modifying unintended records.

DELETE Command

The DELETE command is used to remove records from a table.

SQL
DELETE FROM Students
WHERE StudentId = 101;
Important: Always check the WHERE condition before executing DELETE.

ALTER Command

The ALTER command is used to change the structure of an existing database object.

SQL
ALTER TABLE Students
ADD Email VARCHAR(100);

DROP Command

The DROP command is used to remove a database object.

SQL
DROP TABLE Students;
Important: DROP TABLE removes the table and its stored data.

SQL Command Flow

SQL commands are sent to SQL Server, processed by the database engine and then the required result or operation is returned.

SQL Server

                                                             User
                                                              ↓
                                                          SQL Command
                                                              ↓
                                                          SQL Server
                                                              ↓
                                                          Database Engine
                                                              ↓
                                                          Database / Table
                                                              ↓
                                                           Result

SQL Commands Example

SQL
CREATE TABLE Students
(
    StudentId INT,
    StudentName VARCHAR(100),
    Age INT
);

INSERT INTO Students
VALUES (101, 'Rahul', 22);

SELECT *
FROM Students;

UPDATE Students
SET Age = 23
WHERE StudentId = 101;

DELETE FROM Students
WHERE StudentId = 101;

Summary

In this section, we learned about common SQL commands including CREATE, SELECT, INSERT, UPDATE, DELETE, ALTER and DROP. These commands are used to create, retrieve, modify and manage data and database objects in SQL Server.