This repository contains the implementation of four database tasks performed using MySQL Workbench and Microsoft SQL Server. The tasks demonstrate practical knowledge of SQL including joins, advanced data analysis, database migration, and backup & recovery.
Database Name: company_db
Tables created:
- Employees
- Departments
- Salaries
These tables were used across all tasks to demonstrate different SQL concepts.
To combine data from multiple tables using different types of SQL joins.
- Created tables Employees and Departments in the
company_dbdatabase. - Inserted sample data into both tables.
- Executed different types of joins to retrieve meaningful combined data.
1. INNER JOIN
- Retrieves only matching records from both tables.
SELECT e.emp_name, d.dept_name
FROM Employees e
INNER JOIN Departments d
ON e.dept_id = d.dept_id;2. LEFT JOIN
- Retrieves all records from the left table (Employees) and matching records from Departments.
SELECT e.emp_name, d.dept_name
FROM Employees e
LEFT JOIN Departments d
ON e.dept_id = d.dept_id;3. RIGHT JOIN
- Retrieves all records from the right table (Departments) and matching records from Employees.
SELECT e.emp_name, d.dept_name
FROM Employees e
RIGHT JOIN Departments d
ON e.dept_id = d.dept_id;4. FULL JOIN (Simulated in MySQL)
Since MySQL does not directly support FULL JOIN, it was simulated using UNION.
SELECT e.emp_name, d.dept_name
FROM Employees e
LEFT JOIN Departments d ON e.dept_id = d.dept_id
UNION
SELECT e.emp_name, d.dept_name
FROM Employees e
RIGHT JOIN Departments d ON e.dept_id = d.dept_id;Successfully combined data from multiple tables and understood how different joins return different result sets.
To perform advanced data analysis using SQL features such as:
- Window Functions
- Subqueries
- Common Table Expressions (CTEs)
- Created a Salaries table.
- Inserted salary data for employees.
- Performed analytical queries to identify trends and patterns in the dataset.
Finding employees whose salary is higher than the average salary.
SELECT emp_id, salary
FROM Salaries
WHERE salary > (
SELECT AVG(salary) FROM Salaries
);Ranking employees based on salary.
SELECT emp_id, salary,
RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM Salaries;Calculating the average salary per department.
WITH DeptSalary AS (
SELECT d.dept_name, AVG(s.salary) AS avg_salary
FROM Employees e
JOIN Departments d ON e.dept_id = d.dept_id
JOIN Salaries s ON e.emp_id = s.emp_id
GROUP BY d.dept_name
)
SELECT * FROM DeptSalary;Used advanced SQL features to analyze data and generate insights from relational datasets.
To migrate data from MySQL to Microsoft SQL Server while maintaining data integrity.
-
Created the
company_dbschema in SQL Server. -
Recreated tables:
- Employees
- Departments
- Salaries
-
Migrated the data from MySQL to SQL Server using SQL insert scripts.
-
Verified that data was transferred correctly.
Row counts were compared between both databases.
SELECT COUNT(*) FROM Employees;
SELECT COUNT(*) FROM Departments;
SELECT COUNT(*) FROM Salaries;If the row counts matched in both databases, the migration was considered successful.
The migration process successfully transferred data from MySQL to SQL Server without data loss.
To demonstrate how to back up a database and restore it in case of failure.
-
Opened MySQL Workbench.
-
Navigated to:
Server → Data Export -
Selected the
company_dbdatabase. -
Chose Export to Self-Contained File.
-
Generated a backup file:
company_db_backup.sql
- Simulated a database failure by dropping the database.
DROP DATABASE company_db;- Restored the database using:
Server → Data Import
-
Selected the previously created backup file.
-
Imported the database to recreate tables and data.
USE company_db;
SELECT COUNT(*) FROM Employees;
SELECT COUNT(*) FROM Departments;
SELECT COUNT(*) FROM Salaries;Matching record counts confirmed that the database was successfully restored.
This project demonstrated key database management concepts including:
- SQL joins and relational data retrieval
- Advanced analytical queries using window functions and CTEs
- Cross-platform database migration
- Database backup and recovery procedures
These tasks provided practical experience with real-world database operations using MySQL Workbench and Microsoft SQL Server.