1 · Introduction & Architecture

1.1 What is SQL Server?

Microsoft SQL Server is a relational database management system (RDBMS) with a modular database engine, a storage engine, a query processor, and integrated services for reporting, integration, analysis, machine learning, and graph queries.

1.2 Core Components

1.3 Edition Matrix (Developer → Enterprise)

EditionCPU LimitMemory LimitKey Features
Express1 socket / 4 cores1 GB RAM / 10 GB DBFree starter edition
StandardUp to 24 cores128 GBCore engine + basic HA
EnterpriseOS maxOS maxAll features, Always On, partitioning, compression
DeveloperOS maxOS maxEnterprise feature‑set, non‑production

-- Verify edition & version
SELECT  @@VERSION   AS 'Build',
        SERVERPROPERTY('Edition')       AS 'Edition',
        SERVERPROPERTY('ProductLevel')  AS 'Service Pack';
			

2 · Installation & Configuration

2.1 Setup Checklist

  1. Download ISO (choose edition & language).
  2. Run setup.exe → New SQL Server stand‑alone installation.
  3. Select features (Engine, SSMS, SSIS etc.).
  4. Choose default vs named instance.
  5. Configure service accounts using Managed Service Accounts.
  6. Pick mixed vs Windows authentication; add sysadmin logins.
  7. Configure data, log, TempDB locations on separate disks.
  8. Install latest CU or GDR after setup.

2.2 Baseline Configuration Scripts


-- Set max memory (~80 % of total for dedicated box)
EXEC sys.sp_configure 'show advanced options', 1;  RECONFIGURE;
EXEC sys.sp_configure 'max server memory (MB)', 32768;  RECONFIGURE;

-- Enable instant file initialisation
EXEC sys.sp_configure 'xp_cmdshell', 1;  RECONFIGURE;
			

3 · Database Objects

3.1 Databases


-- Create a new database
CREATE DATABASE SalesDB
 ON  ( NAME = SalesDB_data,
       FILENAME = 'D:\MSSQL\Data\SalesDB.mdf',
       SIZE = 4GB, FILEGROWTH = 512MB )
 LOG ON ( NAME = SalesDB_log,
       FILENAME = 'L:\MSSQL\Logs\SalesDB.ldf',
       SIZE = 1GB, FILEGROWTH = 256MB );
			

3.2 Tables & Constraints


CREATE TABLE dbo.Customers(
    CustomerID  INT IDENTITY(1,1) PRIMARY KEY,
    FirstName   NVARCHAR(50)   NOT NULL,
    LastName    NVARCHAR(50),
    Email       NVARCHAR(255)  UNIQUE,
    CreatedAt   DATETIME2      DEFAULT sysdatetime()
);
			

3.3 Indexes & Partitioning

Clustered indexes define the physical order; non‑clustered provide separate tree‑structures. Partitioning improves manageability for very large tables.


CREATE NONCLUSTERED INDEX IX_Customers_Email
    ON dbo.Customers(Email);

-- Partition function by year
CREATE PARTITION FUNCTION pf_Sales (DATE)
AS RANGE RIGHT FOR VALUES ('2023‑12‑31', '2024‑12‑31');
			

4 · T‑SQL Essentials

4.1 Data Types

4.2 Language Categories

CategoryPurposeExamples
DDLDefine schemaCREATE, ALTER, DROP
DMLManipulate dataSELECT, INSERT, UPDATE, DELETE
DCLControl permissionsGRANT, DENY, REVOKE
TCLTransactional opsBEGIN TRAN, COMMIT, ROLLBACK

4.3 Stored Procedures & Functions


CREATE PROCEDURE dbo.GetCustomer
    @CustomerID INT
AS
BEGIN
    SET NOCOUNT ON;
    SELECT * FROM dbo.Customers WHERE CustomerID = @CustomerID;
END;

CREATE FUNCTION dbo.fn_TotalOrders(@CustomerID INT)
RETURNS MONEY
AS
BEGIN
    RETURN ( SELECT SUM(Amount) FROM dbo.Orders WHERE CustomerID = @CustomerID );
END;
			

5 · Advanced Query Techniques

5.1 Joins & Set Operations


SELECT  c.FirstName, o.OrderID, o.Amount
FROM    dbo.Customers      AS c
JOIN    dbo.Orders         AS o ON o.CustomerID = c.CustomerID
UNION ALL
SELECT  ... -- additional sets
			

5.2 Window Functions


SELECT  CustomerID,
        Amount,
        SUM(Amount) OVER (PARTITION BY CustomerID ORDER BY OrderDate ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal
FROM    dbo.Orders;
			

5.3 Common Table Expressions (CTE)


;WITH Rec (Level, CategoryID) AS
(
    SELECT 1, CategoryID FROM dbo.Categories WHERE ParentID IS NULL
    UNION ALL
    SELECT r.Level+1, c.CategoryID
    FROM dbo.Categories c JOIN Rec r ON c.ParentID = r.CategoryID
)
SELECT * FROM Rec;
			

6 · Concurrency & Transactions

6.1 Isolation Levels

Choose balance between consistency & throughput:

6.2 Deadlock Diagnostics


-- Enable trace flag 1222
DBCC TRACEON (1222, -1);

-- View recent deadlocks (SQL Server 2019+)
SELECT * FROM sys.dm_os_ring_buffers
WHERE ring_buffer_type = 'RING_BUFFER_DEADLOCK';
			

7 · Security

7.1 Authentication

7.2 Roles & Permissions


CREATE LOGIN report_reader WITH PASSWORD = 'Str0ngPa$$word!';
CREATE USER  report_reader FOR LOGIN report_reader;
EXEC sp_addrolemember 'db_datareader', 'report_reader';
			

7.3 Encryption

8 · Performance Tuning & Optimisation

8.1 Indexing Strategy

Use clustered index on narrow, ever‑increasing key; cover frequent seek predicates with non‑clustered indexes; implement filtered indexes for sparse data.

8.2 Query Store & Plan Forcing


ALTER DATABASE SalesDB SET QUERY_STORE = ON;
EXEC sys.sp_query_store_force_plan @query_id = 123, @plan_id = 456;
			

8.3 DMVs for Hotspots


SELECT  TOP 10
        qs.execution_count,
        qs.total_worker_time/qs.execution_count AS avg_cpu,
        qs.total_logical_reads/qs.execution_count AS avg_reads,
        qs.query_hash
FROM    sys.dm_exec_query_stats qs
ORDER BY avg_cpu DESC;
			

9 · High Availability & Disaster Recovery

9.1 Backup & Restore


BACKUP DATABASE SalesDB
  TO DISK = '\\Backup\SalesDB_full.bak'
  WITH COMPRESSION, CHECKSUM;
			
RESTORE DATABASE SalesDB
  FROM DISK = 'D:\Restore\SalesDB_full.bak'
  WITH MOVE 'SalesDB_data' TO 'D:\Data\SalesDB.mdf',
       MOVE 'SalesDB_log'  TO 'L:\Logs\SalesDB.ldf',
       RECOVERY;
			

9.2 Log Shipping & Mirroring

Log shipping = scheduled log backups + restore jobs; Database mirroring (SYNCHROUS or ASYNC) adds automatic failover with a witness.

9.3 Always On Availability Groups

10 · Monitoring & Maintenance

10.1 Automation via SQL Agent

10.2 Extended Events & PerfMon


-- Create lightweight XE session
CREATE EVENT SESSION TrackLongQueries
ON SERVER
ADD EVENT sqlserver.sql_statement_completed
    (WHERE duration > 5000000)
ADD TARGET package0.event_file (SET filename = 'D:\XE\LongQueries.xel')
WITH (STARTUP_STATE = ON);
			

11 · Data Integration & BI

11.1 SSIS (ETL)

Graphical packages move/transform data from heterogeneous sources with connections, transformations, and destinations.

11.2 SSRS & Power BI Integration

SSRS delivers pixel‑perfect paginated reports. Power BI builds dashboards by live‑querying Analysis Services or DirectQuery.

11.3 SSAS Cubes & Tabular Models

Multidimensional cubes for MOLAP; Tabular models (column‑store + xVelocity). DAX & MDX languages for analytics.

12 · Cloud & Hybrid Deployments

12.1 Azure SQL Database

12.2 Managed Instance vs VM vs On‑prem

OptionAdmin ControlPatchingNetwork Isolation
Azure SQL DBLimitedAutomaticPublic endpoint / Private Link
Managed InstanceHighAutomaticVNet‑only
SQL on VMFull (root)User‑drivenVNet / hybrid

13 · Tools & Ecosystem

14 · Best Practices & Resources

14.1 Operational Guidelines

14.2 Learning Paths

  1. Microsoft Learn modules for T‑SQL, Azure SQL.
  2. SQL Server Internals by Kalen Delaney.
  3. Pro SQL Server Wait Statistics by Enrico van de Laar.
  4. Community: #sqlhelp on Twitter, SQLServerCentral forums.