Tutorials SQL Server Tutorial

Data Types — Complete Guide

Data Types — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of SQL Server Tutorial on Toolliyo Academy.

On this page

SQL Server Tutorial · Lesson 9 of 100

Data Types

SQL basicsQueriesAdvanced

SQL basics · 1 — SELECT · ~6 min · SQL — Foundations

What is this?

Each column has a type: INT, DECIMAL, NVARCHAR, DATETIME2, BIT, UNIQUEIDENTIFIER, and more. The type limits size, sorting, and allowed values.

Why should you care?

Wrong types waste space or break money math — DECIMAL for currency, not FLOAT; DATETIME2 over legacy DATETIME for new work.

See it live — copy this example

Run in SQL Server Management Studio (SSMS) or Azure Data Studio.

USE DataVerse;
IF OBJECT_ID(N'dbo.Products', N'U') IS NOT NULL DROP TABLE dbo.Products;
CREATE TABLE dbo.Products (
    ProductId   INT IDENTITY(1,1) PRIMARY KEY,
    Sku         VARCHAR(32) NOT NULL,
    Name        NVARCHAR(200) NOT NULL,
    PriceInr    DECIMAL(10,2) NOT NULL,
    InStock     BIT NOT NULL CONSTRAINT DF_Products_InStock DEFAULT (1),
    ListedOn    DATE NOT NULL
);
INSERT INTO dbo.Products (Sku, Name, PriceInr, ListedOn)
VALUES ('HD-100', N'Noise Cancelling Headphones', 4999.00, '2026-01-15');
SELECT ProductId, Sku, PriceInr, InStock FROM dbo.Products;

What happened?

  • DECIMAL(10,2) keeps paise exact.
  • BIT stores true/false stock.
  • DATE stores calendar day without time.
  • NVARCHAR holds Unicode product names.

Practice next

  1. Create dbo.Products with the script.
  2. Insert a second product with InStock = 0.
  3. Query WHERE PriceInr > 1000.
  4. Add WeightGrams INT NULL and update one row.
  5. Change ListedOn to DATETIME2 and insert with a time.

Remember

Pick types that match real data. Money → DECIMAL; flags → BIT; text → NVARCHAR. Bad types cause bugs and wasted storage.

Catalog price must not drift

DataVerse Products.PriceInr is DECIMAL(10,2) for GST invoices.

Outcome: Invoice totals match the cart to the paisa.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Mid PDF Detailed
What are the differences between SQL and NoSQL databases?
Short answer: SQL Databases (Relational Databases): These are structured databases that use Structured Query Language (SQL) for defining and manipulating data. Explain a bit more They store data in tables with rows and c…
Mid PDF Detailed
Slower Queries: Fragmented indexes cause the database engine to read more data?
Short answer: pages, slowing down query performance. Real-world example (ShopNest) ShopNest adds an index on Orders(CustomerId, CreatedAt) because “my recent orders” is queried constantly. Say this in the interview Defin…
Junior PDF Detailed
What are the differences between SQL and NoSQL databases?
Short answer: And allow storage of unstructured or semi-structured data. They don't require a fixed schema and are often used for large-scale applications where flexibility, scalability, nd speed are more important than…
Mid PDF Detailed
Shared Database, Shared Schema:?
Short answer: All tenants share the same database and tables. A tenant identifier (e.g., tenant_id) is used to segregate data. Pros: Easier to maintain and scale. Cons: Can lead to security and data isolation issues. Say…
Mid PDF Detailed
Normalize the Database: Apply normalization rules (1NF, 2NF, 3NF) to reduce?
Short answer: redundancy by eliminating unnecessary duplication. Real-world example (ShopNest) Product and Category are separate tables (normalized). The order line stores product id + price snapshot—not a giant duplicat…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

SQL Server Tutorial
Course syllabus

SQL Server Tutorial

SQL — Foundations
SQL — SQL Queries & Clauses
SQL — Joins & Relationships
SQL — Indexing & Performance
SQL — Stored Procedures & Functions
SQL — Transactions & Concurrency
SQL — Advanced SQL Server
SQL — Security & High Availability
SQL — 2022 & Cloud
SQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details