Databses & T-SQL Course

Overview

Learning Objectives

This outline is designed for a comprehensive course on SQL, focusing on database management, querying, and data manipulation using SQL. The course includes both theoretical concepts and practical hands-on exercises

Prerequisites

While SQL is a beginner-friendly language, there are a few basic prerequisites that will help students get the most out of an SQL course. These prerequisites ensure that learners have the foundational knowledge needed to understand and apply SQL concepts effectively.

Undergraduate Degree in Computer Sceince, or Related Field

Course Outline

Module 1. Introduction to Databases and T-SQL

Overview of Databases

What is a database?

Types of databases: Relational vs. Non-relational databases

Introduction to database management systems (DBMS)

What is SQL?

Definition of SQL

History and evolution of SQL

Types of SQL commands: DDL, DML, DCL, TCL

Basic Database Design

Tables, rows, and columns

Keys: Primary Key, Foreign Key

Basic normalization concepts

Module 2. SQL Basics

SELECT Statement

Syntax of SELECT

Selecting all columns (SELECT *)

Selecting specific columns

Filtering Data

WHERE clause

Comparison operators: =, <, >, <=, >=, <>

Logical operators: AND, OR, NOT

IN, BETWEEN, LIKE, and IS NULL

Sorting Data

ORDER BY clause (ascending, descending)

Sorting by multiple columns

Sorting Data

ORDER BY clause (ascending, descending)

Sorting by multiple columns

Limiting Data

Using LIMIT (or TOP in some systems)

Module 3. Aggregating and Grouping Data

Aggregation Functions

COUNT(), SUM(), AVG(), MIN(), MAX()

GROUP BY Clause

Grouping data by one or more columns

Using aggregate functions with GROUP BY

HAVING Clause

Filtering grouped data using HAVING

DISTINCT Keyword

Removing duplicate rows from result sets

Module 4. Joining Tables

Types of Joins

INNER JOIN

LEFT JOIN (OUTER JOIN)

RIGHT JOIN (OUTER JOIN)

FULL OUTER JOIN

CROSS JOIN

Join Conditions

Using ON clause to specify join conditions

Self-joins and recursive joins

Combining Multiple Joins

Joining more than two tables

Using subqueries with joins

Module 5. Subqueries

Introduction to Subqueries

What is a subquery?

Types of subqueries: scalar, column, and table subqueries

Using Subqueries in SELECT, INSERT, UPDATE, DELETE

Subqueries in WHERE, FROM, and HAVING clauses

Correlated vs. non-correlated subqueries

Nested Queries

Subqueries within subqueries

Module 6. Modifying Data

INSERT Statement

Syntax for inserting single and multiple rows

Inserting data using SELECT

...

UPDATE Statement

Updating data in one or more columns

Using WHERE to specify which records to update

...

DELETE Statement

Deleting data from a table

Deleting all rows vs. selective deletion with WHERE

...

Transactions and Commit/Rollback

Understanding transactions in SQL

COMMIT and ROLLBACK commands

Transaction isolation levels

Module 7. Database Design and Normalization

Normalization Basics

Why normalization is important

First, Second, and Third Normal Forms (1NF, 2NF, 3NF)

Denormalization and trade-offs

Creating Tables and Constraints

Defining table structures: CREATE TABLE

Adding constraints: PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE

Defining default values and check constraints

Altering and Dropping Tables

ALTER TABLE to add, modify, or drop columns

Dropping tables or constraints

Module 8. Advanced SQL Concepts

Indexes

What are indexes?

Types of indexes: Unique, Composite, Full-text

Creating and managing indexes

Performance implications of indexes

Views

What is a view?

Creating and using views

Updating data through views (if possible)

Stored Procedures and Functions

Creating and using stored procedures

Differences between stored procedures and functions

Input/output parameters

Triggers

What are triggers?

Creating triggers for INSERT, UPDATE, DELETE

Use cases and limitations of triggers

Transactions and Concurrency

ACID properties: Atomicity, Consistency, Isolation, Durability

Handling concurrent transactions and locks

Module 9. SQL Optimization and Performance

Query Optimization

Analyzing execution plans

Using EXPLAIN and other tools to optimize queries

Avoiding common performance pitfalls

Indexing for Performance

Choosing which columns to index

Analyzing index usage

Index maintenance

Database Tuning

Caching and memory management

Partitioning large tables for performance

Optimizing JOINs and subqueries

Module 10. SQL Security

SQL Injection

Understanding SQL injection attacks

Preventing SQL injection through parameterized queries

User Roles and Permissions

Managing user access with GRANT and REVOKE

Role-based access control

Database Auditing

Tracking and logging changes in the database

Auditing SQL queries and operations

Module 11. Advanced Topics and Project Work

Working with Complex Queries

Recursive queries (Common Table Expressions or CTEs)

Pivoting and unpivoting data

Window functions (e.g., ROW_NUMBER(), RANK(), PARTITION BY)

Database Migration and Backup

Backup strategies and types (full, incremental)

Restoring and migrating databases

Capstone Project

Practical application of all learned SQL concepts

Creating a database, writing queries, and optimizing performance

. . .