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 Server Data Types

SQL Server data types define the kind of data that can be stored in a column, variable or expression. Choosing the correct data type helps SQL Server store data efficiently and maintain data accuracy.

What are Data Types?

A data type specifies what kind of value can be stored in a database column or variable. For example, a student's name can be stored using a character data type, while a student's age can be stored using a numeric data type.

Every column in a SQL Server table has a data type. The data type determines the type of values that the column can contain.

Why are Data Types Important?

Selecting the appropriate data type is important because it affects storage, performance and the type of values that can be stored in a column.

  • Helps maintain data accuracy.
  • Controls the type of values stored in a column.
  • Helps use database storage efficiently.
  • Makes database design more organized.

How Data Types Work

When creating a table, we define a data type for every column. SQL Server then uses that definition when storing and processing the data.

SQL Server

                                                                Column
                                                                   ↓
                                                                Data Type
                                                                   ↓
                                                                Allowed Values
                                                                   ↓
                                                                Stored Data
            

SQL Server Data Type Categories

SQL Server provides different categories of data types for storing different kinds of information.

Category Used For Examples
Numeric Numbers and mathematical values int, bigint, decimal, float
Character & String Text and character data char, varchar, nchar, nvarchar
Date & Time Date and time values date, datetime, time
Binary Binary data binary, varbinary
Other Special types of data bit, uniqueidentifier, xml

Common SQL Server Data Types

Data Type Purpose Example
int Stores integer numbers. 100
varchar Stores variable-length character data. 'Rahul'
nvarchar Stores variable-length Unicode character data. N'Rahul'
decimal Stores exact numeric values. 12500.50
date Stores date values. '2026-10-02'
bit Stores Boolean-like values. 0 / 1

Example: Using Data Types

The following example creates a Students table using different SQL Server data types.

SQL
CREATE TABLE Students
(
    StudentId INT,
    StudentName VARCHAR(100),
    Age INT,
    Fees DECIMAL(10,2),
    BirthDate DATE,
    IsActive BIT
);

Here, each column uses a data type suitable for the kind of information that it stores.

Choosing the Correct Data Type

The data type should be selected according to the kind of data that the column needs to store.

Requirement Suitable Data Type
Student ID INT
Student Name VARCHAR / NVARCHAR
Course Fees DECIMAL
Date of Birth DATE
Active / Inactive Status BIT
Important

Always choose a data type based on the actual data that needs to be stored. Using an inappropriate data type can lead to unnecessary storage usage or unexpected results.

Summary

In this section, we learned what SQL Server data types are, why they are important and the major categories of data types. We also looked at common data types and how to choose an appropriate data type when designing a table.