Skip to content

Introduction to SQL Server

What is SQL Server?

SQL Server is a relational database management system (RDBMS) developed by Microsoft. It stores and retrieves data requested by applications, making it a critical component in enterprise software systems.

┌─────────────────────────────────────────────────────────────────┐
│                    How SQL Server Works                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│   Application Layer                                              │
│   ─────────────────                                              │
│   ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐           │
│   │  Web    │  │ Desktop │  │  API    │  │ Mobile  │           │
│   │  App    │  │   App   │  │ Service │  │   App   │           │
│   └────┬────┘  └────┬────┘  └────┬────┘  └────┬────┘           │
│        │            │            │            │                  │
│        └────────────┴─────┬──────┴────────────┘                  │
│                           │                                      │
│                           ▼                                      │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │              SQL Server Database Engine                  │   │
│   │  ┌─────────────┐  ┌──────────────┐  ┌───────────────┐   │   │
│   │  │   Query     │  │   Storage    │  │   Security    │   │   │
│   │  │  Processor  │  │    Engine    │  │    Layer      │   │   │
│   │  └─────────────┘  └──────────────┘  └───────────────┘   │   │
│   └─────────────────────────────────────────────────────────┘   │
│                           │                                      │
│                           ▼                                      │
│   ┌─────────────────────────────────────────────────────────┐   │
│   │                    Data Files                            │   │
│   │              (.mdf, .ndf, .ldf files)                    │   │
│   └─────────────────────────────────────────────────────────┘   │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Key Concepts

Database

A database is a container that holds related tables, views, stored procedures, and other objects. One SQL Server instance can host multiple databases.

sql
-- List all databases on the server
SELECT name, database_id, create_date
FROM sys.databases;

Table

A table is where data is stored in rows and columns, similar to a spreadsheet.

sql
-- Example: Customers table
CREATE TABLE Customers (
    CustomerID INT PRIMARY KEY,
    Name NVARCHAR(100),
    Email NVARCHAR(255),
    CreatedAt DATETIME DEFAULT GETDATE()
);

Schema

A schema is a namespace that groups related database objects. The default schema is dbo (database owner).

┌─────────────────────────────────────────────────────────────────┐
│                      Database: CompanyDB                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│   Schema: dbo (default)        Schema: Sales        Schema: HR  │
│   ────────────────────         ─────────────        ──────────  │
│   • Users                      • Orders             • Employees │
│   • Settings                   • Products           • Salaries  │
│   • Logs                       • Customers          • Departments│
│                                                                  │
└─────────────────────────────────────────────────────────────────┘
sql
-- Access table with schema
SELECT * FROM dbo.Customers;
SELECT * FROM Sales.Orders;
SELECT * FROM HR.Employees;

SQL Server Architecture

Instance

An instance is a single installation of SQL Server. You can have multiple instances on one machine.

┌─────────────────────────────────────────────────────────────────┐
│                    SQL Server Instances                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  Server: MYCOMPUTER                                              │
│  ─────────────────                                               │
│                                                                  │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐  │
│  │ Default Instance│  │ Named Instance  │  │ Named Instance  │  │
│  │   (MSSQLSERVER) │  │  (SQLEXPRESS)   │  │    (DEVDB)      │  │
│  ├─────────────────┤  ├─────────────────┤  ├─────────────────┤  │
│  │ • ProductionDB  │  │ • TestDB        │  │ • DevDB         │  │
│  │ • ReportingDB   │  │ • SandboxDB     │  │ • FeatureDB     │  │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘  │
│                                                                  │
│  Connection Strings:                                             │
│  • MYCOMPUTER (default)                                          │
│  • MYCOMPUTER\SQLEXPRESS                                         │
│  • MYCOMPUTER\DEVDB                                              │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

System Databases

SQL Server has four system databases that are essential for operation:

DatabasePurpose
masterCore configuration, logins, server settings
modelTemplate for new databases
msdbSQL Server Agent jobs, backups, alerts
tempdbTemporary tables, query processing

Never Modify System Databases Directly

System databases contain critical configuration. Always use official tools and commands to make changes.

SQL Server Components

┌─────────────────────────────────────────────────────────────────┐
│                    SQL Server Components                         │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  Core Database Engine                                            │
│  ────────────────────                                            │
│  ┌───────────────────────────────────────────────────────────┐  │
│  │  • Storage Engine - Data storage and retrieval            │  │
│  │  • Query Processor - Parse, optimize, execute queries     │  │
│  │  • Buffer Manager - Memory management                     │  │
│  │  • Transaction Manager - ACID compliance                  │  │
│  └───────────────────────────────────────────────────────────┘  │
│                                                                  │
│  Additional Services                                             │
│  ───────────────────                                             │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐              │
│  │    SSIS     │  │    SSRS     │  │    SSAS     │              │
│  │ Integration │  │  Reporting  │  │  Analysis   │              │
│  │  Services   │  │  Services   │  │  Services   │              │
│  └─────────────┘  └─────────────┘  └─────────────┘              │
│                                                                  │
│  • SSIS: ETL (Extract, Transform, Load) data pipelines          │
│  • SSRS: Generate and distribute reports                        │
│  • SSAS: OLAP cubes and data mining                             │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

SQL Server History

VersionYearKey Features
SQL Server 7.01998Complete rewrite, modern architecture
SQL Server 20002000XML support, user-defined functions
SQL Server 20052005CLR integration, SSIS, SSRS
SQL Server 20082008Spatial data, FILESTREAM
SQL Server 20122012AlwaysOn, columnstore indexes
SQL Server 20142014In-memory OLTP
SQL Server 20162016JSON support, temporal tables
SQL Server 20172017Linux support, graph databases
SQL Server 20192019Big Data Clusters, UTF-8
SQL Server 20222022Azure integration, ledger tables

Use Cases for SQL Server

Enterprise Applications

┌─────────────────────────────────────────────────────────────────┐
│                    Enterprise Use Cases                          │
├─────────────────────────────────────────────────────────────────┤
│                                                                  │
│  E-Commerce Platform                                             │
│  ───────────────────                                             │
│  Products ──┬── Orders ──┬── Customers                          │
│             │            │                                       │
│             └── Inventory└── Payments                           │
│                                                                  │
│  Healthcare System                                               │
│  ─────────────────                                               │
│  Patients ──┬── Appointments ──┬── Medical Records              │
│             │                  │                                 │
│             └── Prescriptions ─┴── Insurance Claims             │
│                                                                  │
│  Financial Application                                           │
│  ─────────────────────                                           │
│  Accounts ──┬── Transactions ──┬── Audit Logs                   │
│             │                  │                                 │
│             └── Statements    ─┴── Compliance Reports           │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Real-World Example: E-Commerce Database

sql
-- Create the Products table
CREATE TABLE Products (
    ProductID INT PRIMARY KEY IDENTITY(1,1),
    ProductName NVARCHAR(100) NOT NULL,
    Description NVARCHAR(500),
    Price DECIMAL(10,2) NOT NULL,
    StockQuantity INT DEFAULT 0,
    CategoryID INT,
    CreatedAt DATETIME2 DEFAULT SYSDATETIME()
);

-- Create the Customers table
CREATE TABLE Customers (
    CustomerID INT PRIMARY KEY IDENTITY(1,1),
    FirstName NVARCHAR(50) NOT NULL,
    LastName NVARCHAR(50) NOT NULL,
    Email NVARCHAR(255) UNIQUE NOT NULL,
    Phone NVARCHAR(20),
    RegistrationDate DATE DEFAULT GETDATE()
);

-- Create the Orders table
CREATE TABLE Orders (
    OrderID INT PRIMARY KEY IDENTITY(1,1),
    CustomerID INT FOREIGN KEY REFERENCES Customers(CustomerID),
    OrderDate DATETIME2 DEFAULT SYSDATETIME(),
    TotalAmount DECIMAL(12,2),
    Status NVARCHAR(20) DEFAULT 'Pending'
);

SQL Server vs Competitors

FeatureSQL ServerOraclePostgreSQLMySQL
CostExpress (Free), CommercialCommercialFreeFree
PlatformWindows, LinuxAllAllAll
ACID CompliantYesYesYesYes (InnoDB)
JSON SupportGoodGoodExcellentGood
ReplicationBuilt-inBuilt-inBuilt-inBuilt-in
ClusteringAlwaysOnRACPatroniMySQL Cluster
IDESSMS (Excellent)SQL DeveloperpgAdminWorkbench

When to Use SQL Server

Best For

  • Microsoft ecosystem - .NET, Azure, Windows Server
  • Enterprise applications - Built-in compliance and security
  • Business Intelligence - Native SSRS, SSIS, Power BI integration
  • Hybrid cloud - Seamless Azure SQL Database sync

Consider Alternatives When

  • Budget is limited - PostgreSQL is fully free
  • Unix/Linux only - PostgreSQL or MySQL may be more natural
  • Simple applications - SQLite might be sufficient
  • NoSQL requirements - Consider MongoDB or CosmosDB

Summary

In this chapter, you learned:

  • SQL Server is Microsoft's enterprise relational database system
  • Databases contain tables, views, stored procedures, and other objects
  • SQL Server uses T-SQL (Transact-SQL) for queries
  • Key components include the Database Engine, SSIS, SSRS, and SSAS
  • SQL Server is ideal for enterprise applications in the Microsoft ecosystem

Ready to install SQL Server? Continue to Chapter 2: Installation!