Introduction

In Microsoft SQL Server, every column must have a data type.

👉 Data type defines:

Why Data Types Are Important?

Without proper data types:

👉 With correct data types:

Types of Data Types in SQL Server

1️⃣ Numeric Data Types

INT (Integer)

👉 Stores whole numbers

CREATE TABLE Student (
    Id INT,
    Age INT
);

INSERT INTO Student VALUES (1, 20);

✔ Output:

👉 Use When:

BIGINT

👉 Stores very large numbers

BIGINT

👉 Use When:

DECIMAL / NUMERIC

👉 Stores exact decimal values

Price DECIMAL(10,2)

👉 Example:

INSERT INTO Product VALUES (101, 199.99);

✔ Output:

👉 Use When:

FLOAT

👉 Stores approximate decimal values

Value FLOAT

👉 Use When:

⚠️ Note: Not accurate like DECIMAL

2️⃣ Character (String) Data Types

CHAR

👉 Fixed length string

Code CHAR(5)

👉 Example:

INSERT INTO Test VALUES ('A');

✔ Output:

'A ' (extra spaces added)

👉 Use When:

VARCHAR

👉 Variable length string

Name VARCHAR(50)

👉 Example:

INSERT INTO Student VALUES ('Abhay');

✔ Output:

'Abhay'

👉 Use When:

✅ Saves space

NVARCHAR

👉 Stores Unicode (multiple languages)

Name NVARCHAR(50)

👉 Example:

INSERT INTO Student VALUES (N'અભય');

✔ Output:

અભય

👉 Use When:

3️⃣ Date and Time Data Types

DATE

👉 Stores only date

DOB DATE

✔ Example:

2026-03-31

DATETIME

👉 Stores date + time

CreatedAt DATETIME

✔ Example:

2026-03-31 10:30:00

DATETIME2 (Recommended)

👉 More accurate than DATETIME

👉 Use When:

TIME

👉 Stores only time

LoginTime TIME

✔ Output:

10:30:00

4️⃣ Boolean Data Type

BIT

👉 Stores only:

IsActive BIT

✔ Example:

👉 Use When:

5️⃣ Binary Data Types

VARBINARY

👉 Stores files (images, videos)

ProfileImage VARBINARY(MAX)

👉 Use When:

6️⃣ Unique Identifier

UNIQUEIDENTIFIER

👉 Generates unique ID (GUID)

Id UNIQUEIDENTIFIER DEFAULT NEWID()

✔ Example Output:

A1B2C3D4-5678-90AB-CDEF-1234567890AB

👉 Use When:

7️⃣ Special Data Types

XML

👉 Stores XML data

Data XML

JSON (Stored in NVARCHAR)

👉 SQL Server stores JSON as string

Data NVARCHAR(MAX)

When to Use Which Data Type (Important)

Common Mistakes

Pro Tips (Very Important)

Real-Life Example

CREATE TABLE Employee (
    Id INT,
    Name NVARCHAR(100),
    Salary DECIMAL(10,2),
    DOB DATE,
    IsActive BIT
);

Conclusion

👉 Data types are the foundation of database design

If you choose wrong:

If you choose correct: