- This project demonstrates a complete SQL Server database system for managing employees, departments, payroll, and attendance.
- It includes database design, data insertion, reporting queries, stored procedures, functions, and indexing.
- SQL Server 2022
- T-SQL
- SSMS (SQL Server Management Studio)
- ERD (Database Diagrams)
- SQL Server (T-SQL)
- Database design (3NF)
- Constraints (PK, FK, CHECK, UNIQUE)
- DDL + DML scripting
- Joins, subqueries, CTEs, window functions
- Stored procedures
- Scalar functions
- Indexes (Clustered & Nonclustered)
📌 Dimension Tables:
- Department — Stores department names and codes
- JobRole — Job titles, grades, and department linkage
- Employee — Employee master data (personal + job + department)
📌 Fact Tables:
- Salary — Monthly salary structure (basic, HRA, PF, allowances)
- Attendance — Daily login/logout & working days
- Payroll — Final payroll calculations per month per employee
🔗 Relationships & Integrity:
- All tables linked with Primary–Foreign Key relationships
- Ensures full referential integrity through:
- employee_id
- department_id
- jobrole_id
- salary_id
- Implemented CHECK constraints, UNIQUE constraints, and default values (where needed)
📘 Data Model Diagram:
🧾 Creating and populating tables:
- Sample records:
- Employee list with department, role, salary
- Top 3 employees by salary (per department) using RANK()
- Employees earning above department average
- Latest salary using ROW_NUMBER()
- Department-wise payroll
- Payroll ranking using DENSE_RANK
- Employees with no payroll
- Attendance summary per employee
- Salary vs Department average
- AddNewEmployee
- UpdateEmployeeSalary
- GetDepartmentPayrollReport
- GetEmployeeTotalPayroll (Output parameter)
- GetFullName(EmpID)
- GetTotalPayroll(EmpID)
- Nonclustered index on DepartmentID for faster department-wise queries.
- Clustered index automatically created on EmployeeID (PK).
README.md→ Complete project documentationA.EmpPayroll_CreatingTables.sql→ Database + 6 table creation scriptsB.EmpPayroll_InsertingValues.sql→ 50 employee records + salary + attendance + payrollC.EmpPayroll_ReportingQueries.sql→ Joins, CTEs, window functions, subqueriesD.EmpPayroll_StoredProcedures.sql→ CRUD + salary update + payroll summary SPsE.EmpPayroll_Functions.sql→ Full name & total payroll scalar functionsF.EmpPayroll_Indexes.sql→ Nonclustered index on DepartmentIDimages/→model.jpg→ ER diagram showing the relationships between the tablessnap.jpg→ Snapshot of tables
- How to design normalized databases (3NF)
- Writing clean & optimized T-SQL code
- Using window functions for analytics
- Designing reusable stored procedures
- Improving performance with indexes
- Creating real-world payroll calculations
- Open SQL Server Management Studio (SSMS)
- Run
A.EmpPayroll_CreatingTables.sql - Run
B.EmpPayroll_InsertingValues.sql - Run reporting queries →
C.EmpPayroll_ReportingQueries.sql - Run stored procedures →
D.EmpPayroll_StoredProcedures.sql - Run scalar functions →
E.EmpPayroll_Functions.sql - Run index creation →
F.EmpPayroll_Indexes.sql

