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

Database & Tables Introduction

A database is used to store and organize data, while tables are used to store data in rows and columns. In SQL Server, databases and tables form the foundation for storing and managing structured information.

What is a Database?

A database is a structured collection of information that allows data to be stored, managed and retrieved efficiently.

In SQL Server, a database can contain tables, views, stored procedures, functions and other database objects.

Example

A college application may have a database named CollegeDB that stores student, course and teacher information.

Database Structure

A SQL Server database can contain multiple database objects. A simple structure can be represented as follows:

SQL Server

                                                        Database
                                                           ↓
                                                        Tables
                                                           ↓
                                                        Rows & Columns
                                                           ↓
                                                         Data

Tables are one of the most important objects inside a database because they store the actual data.

What is a Table?

A table is a database object used to store related information in the form of rows and columns.

Each column represents a specific type of information, while each row represents one complete record.

Rows and Columns

Consider a Students table:

StudentId StudentName Age Course
1 Rahul 22 Java
2 Priya 21 .NET
3 Amit 23 Python
  • Column: Defines the type of information stored.
  • Row: Represents one complete record.
  • Table: Collection of related records.

Database and Table Relationship

A database can contain multiple tables. Each table can store data related to a particular entity.

SQL Server

                                                        CollegeDB
                                                           │
                                                           ├── Students
                                                           │
                                                           ├── Courses
                                                           │
                                                           ├── Teachers
                                                           │
                                                           └── Departments

For example, the Students table stores student information, while the Courses table stores course information.

Creating a Database

The CREATE DATABASE statement is used to create a new database in SQL Server.

SQL
CREATE DATABASE CollegeDB;

After executing this statement, SQL Server creates a new database named CollegeDB.

Creating a Table

The CREATE TABLE statement is used to create a table inside a database.

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

This statement creates a table named Students with four columns.

Common Database & Table Operations

Operation SQL Statement Purpose
Create Database CREATE DATABASE Create a new database.
Create Table CREATE TABLE Create a new table.
Alter Table ALTER TABLE Modify table structure.
Drop Table DROP TABLE Remove a table.
Important

A database contains database objects, and tables are primarily used to store structured data in rows and columns. Choosing a proper table structure is important for managing data efficiently.

Summary

In this section, we learned what a database and table are, how databases and tables are organized, the difference between rows and columns, and the basic SQL statements used to create databases and tables.