A beginner-friendly SQL-based project to manage employees and departments using MySQL. This system includes database creation, relational table setup with primary & foreign keys, CRUD operations, aggregate functions, and JOIN queries to simulate a real-world employee management system.
- ✅ Create & use company database
- ✅ Relational table setup (
Employee,Department) - ✅ Primary and foreign key constraints
- ✅ CRUD operations (Create, Read, Update, Delete)
- ✅ Aggregate functions:
SUM(),AVG(),GROUP BY,HAVING - ✅
JOINqueries to fetch employee and department info together
| Column | Type | Constraints |
|---|---|---|
| dept_id | INT | PRIMARY KEY |
| dept_name | VARCHAR(50) | NOT NULL, UNIQUE |
| Column | Type | Constraints |
|---|---|---|
| emp_id | INT | PRIMARY KEY |
| name | VARCHAR(100) | NOT NULL |
| salary | DECIMAL(10,2) | CHECK (salary > 0) |
| doj | DATE | |
| dept_id | INT | FOREIGN KEY → Department(dept_id) |
SELECT * FROM Department;SELECT name, salary
FROM Employee
WHERE salary > 50000
ORDER BY salary DESC;UPDATE Employee
SET salary = 65000
WHERE emp_id = 104;DELETE FROM Employee
WHERE emp_id = 107;SELECT dept_id, SUM(salary) AS total_salary
FROM Employee
GROUP BY dept_id;SELECT e.emp_id, e.name AS employee_name, e.salary, d.dept_name AS department_name
FROM Employee e
JOIN Department d ON e.dept_id = d.dept_id;- Install MySQL and open any MySQL client (Workbench / CLI / phpMyAdmin)
- Run the provided SQL script step by step
- Query the tables to test
Feel free to fork this repo, add new queries, or create issue threads if you find bugs or want improvements!
- ⭐ Star the repository
- 🍴 Fork it
- 📢 Share with friends & developers preparing for interviews
- 🔁 Keep practicing daily!
"Practice makes perfect — keep querying until it's second nature!" 💪