SQL DBA Complete Guide (Basic to
Advanced)
1. SQL Server Basics
- SQL Server is a relational database management system developed by Microsoft.
- Key components: SQLOS (handles memory, scheduling, I/O), Buffer Pool (manages cache),
and Query Processor.
- Instances: Each SQL Server installation can host multiple instances.
- System Databases: master, model, msdb, tempdb.
- Data storage: Data stored in 8KB pages, grouped into extents (8 pages).
2. Installation & Configuration
- Check prerequisites (CPU, Memory, Disk).
- Best practice: Set MAXDOP based on cores, adjust Cost Threshold for Parallelism.
- Configure TempDB files (1 per core up to 8).
- Post-install tasks: enable TCP/IP, set max memory, configure error log retention.
3. Security
- Logins vs Users: Login is at server level, User is at database level.
- Server roles: sysadmin, securityadmin, etc.
- Database roles: db_owner, db_datareader, db_datawriter.
- Permissions: GRANT, DENY, REVOKE.
- Best practices: Use least privilege, enforce strong password policy, use AD authentication.
4. Backup & Recovery
- Backup types: Full, Differential, Log, File/Filegroup, Copy-only.
- Recovery models: Simple, Full, Bulk-Logged.
- Restore scenarios: Point-in-Time recovery with log backups.
- Tail-log backup required for point-of-failure recovery.
5. High Availability & Disaster Recovery (HADR)
- Log Shipping: Automatic restore of transaction logs on standby server.
- Database Mirroring: Real-time database copy (synchronous or asynchronous).
- AlwaysOn Availability Groups: High availability with multiple replicas.
- Failover Cluster Instances (FCI): Uses Windows clustering for HA.
- Replication types: Snapshot, Transactional, Merge.
6. Performance Tuning
- Indexes: Clustered (1 per table), Non-clustered, Filtered, Columnstore.
- Statistics: Ensure auto update is enabled.
- Execution Plans: Analyze query performance.
- Wait Stats: Common waits include CXPACKET, PAGEIOLATCH, LCK_M.
- Blocking/Deadlocks: Use Extended Events or Deadlock Graphs.
7. Maintenance & Automation
- Integrity checks: DBCC CHECKDB.
- Index rebuild vs reorganize based on fragmentation %.
- Update statistics regularly.
- SQL Agent Jobs: Automate backups, index maintenance, alerts.
- Maintenance Plans vs Custom Jobs: Custom jobs give more flexibility.
8. Monitoring & Troubleshooting
- Use SQL Error Logs, Extended Events for troubleshooting.
- Monitor CPU, memory, disk latency using Perfmon.
- Blocking: Identify lead blocker using sys.dm_exec_requests.
- TempDB: Use multiple data files to reduce contention.
- Check database growth patterns and avoid autogrowth issues.
9. Cloud & Hybrid SQL Server
- Azure SQL Database: PaaS service with automated backups, patching.
- Managed Instance: Hybrid features between on-prem and cloud.
- Backups can be stored in Azure Blob.
- Monitor using Azure Monitor & Log Analytics.
10. Advanced Topics
- Partitioning: Split large tables into smaller chunks.
- Compression: Row and Page compression to save storage.
- In-Memory OLTP: Memory-optimized tables for performance.
- RCSI & Snapshot Isolation: Reduce blocking by using versioned rows.
- TDE: Encrypts database at rest.
- Always Encrypted & Dynamic Data Masking for data security.
11. Real-Time Scenarios & Interview Q&A
- Blocking issue: Identify head blocker, check query, kill spid if needed.
- High CPU: Check running queries, missing indexes, parallelism.
- Corruption: Run DBCC CHECKDB, restore from backup if repair not possible.
- Index tuning: Use missing index DMV, execution plans.
- Disaster recovery: Simulate failover, test backups regularly.