UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS
Databases I
Vasileios Evangelos Athanasiou
Student ID: 19390005
Supervisor: Anastasios Tsolakidis, Assistant Professor
Athens, June 2023
The project demonstrates the design and manipulation of a relational database that models a company’s personnel structure, departments, and project assignments.
| Section | Folder / File | Description |
|---|---|---|
| 1 | assign/ |
Assignment material |
| 1.1 | assign/assignment_02.pdf |
Assignment description (English) |
| 1.2 | assign/εργασία_02.pdf |
Assignment description (Greek) |
| 2 | docs/ |
Theoretical documentation |
| 2.1 | docs/SQL-Queries.pdf |
SQL queries theory and examples (English) |
| 2.2 | docs/SQL-Ερωτήματα.pdf |
SQL queries theory and examples (Greek) |
| 3 | src/ |
SQL source code |
| 3.1 | src/new_personnel.sql |
SQL script for personnel database queries |
| 4 | README.md |
Repository overview and instructions |
The database, named new_personnel, consists of four primary tables:
| Table | Description | Primary Key |
|---|---|---|
| DEPT | Department details (Name, Location) | DEPTNO |
| EMP | Employee records (Name, Job, Salary, Hire Date) | EMPNO |
| PROJ | Project descriptions | PROJ_CODE |
| ASSIGN | Relationship between Employees and Projects (Time spent) | (EMPNO, PROJ_CODE) |
The SQL scripts handle the complete setup of the database environment, including:
- Creation of the
new_personneldatabase - Definition of all tables with PRIMARY KEY and FOREIGN KEY constraints
- Population of sample data for departments such as:
- Accounting (Athens)
- Sales (London)
- Research (Athens)
The documentation includes several practical and advanced SQL exercises:
-
Financial Reporting
Calculation of monthly employee earnings (Salary + Commission) and formatting results with currency symbols. -
Service Calculation
Use ofDATEDIFFto compute years of service and filtering employees with more than 20 years of experience. -
Advanced Filtering
Use ofSUBSTRINGandBETWEENto identify employees hired on specific days of the month. -
Correlated Subqueries
Identification of employees who earn the highest salary within their department.
This document serves as a complete laboratory report, demonstrating proficiency in:
-
Data Definition Language (DDL)
CREATE,DROP, and enforcement of table constraints -
Data Manipulation Language (DML)
INSERTstatements for populating database records -
Data Query Language (DQL)
AdvancedSELECTstatements using:IFNULLCONCATFORMAT- Nested and correlated subqueries
This repository contains a relational database creation and SQL query project developed for the Databases I (Database Management) course at the University of West Attica (UNIWA).
It demonstrates database creation, schema definition, data insertion, and advanced SQL querying.
Before using this project, ensure you have the following installed:
- MySQL (recommended)
- Compatible alternatives:
- MariaDB
- PostgreSQL (minor syntax adjustments may be required)
Any SQL client capable of executing .sql scripts:
- MySQL Workbench (recommended)
- phpMyAdmin
- DBeaver
- Command-line MySQL client
Make sure your SQL client is properly connected to your database server.
Open a terminal/command prompt and run:
git clone https://github.com/Data-Bases-1/SQL-Queries.git- Open the repository URL in your browser
- Click Code → Download ZIP
- Extract the ZIP file to a local directory
Navigate to:
src/new_personnel.sqlThis file contains:
- Database creation statements
- Table definitions (
DEPT,EMP,PROJ,ASSIGN) - Primary and foreign key constraints
- Sample data insertion
- Example SQL queries
- Open your SQL client
- Create a new SQL tab
- Open or paste the contents of new_personnel.sql
- Execute the script (Run)
mysql -u your_username -pThen:
SOURCE path/to/new_personnel.sql;After successful execution, verify the setup:
SHOW DATABASES;
USE new_personnel;SHOW TABLES;Expected tables:
DEPTEMPPROJASSIGN
DESCRIBE DEPT;
DESCRIBE EMP;
DESCRIBE PROJ;
DESCRIBE ASSIGN;SELECT * FROM DEPT;
SELECT * FROM EMP;
SELECT * FROM PROJ;
SELECT * FROM ASSIGN;- Navigate to the
docs/directory - Open the report corresponding to your preferred language:
- English:
SQL-Queries.pdf - Greek:
SQL-Ερωτήματα.pdf
- English:
