Categories: SQL Training
Tags:

Introduction: Understanding the Construction ERP Database

A database is the foundation of any data-driven business application. Whether an organisation manages employees, clients, construction projects, quotations, payments or operational expenses, it needs a structured system to store, organise and retrieve information.

For this practical project, we are developing a Construction Company ERP Database using MySQL. The objective is to create a realistic business database that represents the daily operations of a construction company. We will use this database as the foundation for learning SQL, performing Exploratory Data Analysis (EDA), creating analytical views and eventually building interactive dashboards in Microsoft Power BI.

A construction company generally handles several business activities simultaneously. It needs to maintain employee information, assign employees to projects, manage client relationships, prepare quotations, track project budgets, record payments and monitor expenses. Keeping all this information in separate spreadsheets can create duplication, inconsistencies and difficulties when generating reports.

A relational database solves these problems by organising information into multiple interconnected tables. Each table represents a particular business entity, while relationships connect the relevant records.

Our Construction ERP database contains ten primary tables:

  1. Departments
  2. Employees
  3. Clients
  4. Service Types
  5. Projects
  6. Project Assignments
  7. Quotations
  8. Quotation Items
  9. Project Payments
  10. Project Expenses

We will use MySQL to create these tables and establish relationships using primary keys and foreign keys.

1. Creating the Construction ERP Database

Before creating individual tables, we need to create a database.

A database is a structured collection of related tables and other database objects. In our project, we will name the database Construction_ERP.

CREATE DATABASE Construction_ERP;

USE Construction_ERP;

The CREATE DATABASE command creates a new database, while USE selects it as the active database for subsequent SQL operations.

We can now start creating the individual tables.

Note: You can get the Dummy Data for this database here: https://www.kaggle.com/datasets/slidescope/construction-company-erp-database

2. Creating the Database Tables

Table 1: Departments

The departments table stores information about different departments operating within the construction company.

A construction organisation may have departments such as Management, Construction, Architecture, Interior Design, Finance, Human Resources, Procurement and Sales & Client Relations.

CREATE TABLE departments (
    department_id INT AUTO_INCREMENT PRIMARY KEY,
    department_name VARCHAR(100) NOT NULL,
    department_head VARCHAR(150),
    created_at DATE
);

The department_id column is the primary key and uniquely identifies every department. AUTO_INCREMENT automatically generates a new identifier when a record is inserted.

The department_name column stores the department’s name, while department_head records the person responsible for managing it.

Table 2: Employees

The employees table maintains information about the company’s workforce.

It stores employee names, contact information, department assignments, designations, joining dates, employment status and salaries.

CREATE TABLE employees (
    employee_id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(100) NOT NULL,
    last_name VARCHAR(100),
    gender VARCHAR(20),
    date_of_birth DATE,
    email VARCHAR(150) UNIQUE,
    phone VARCHAR(20),
    department_id INT,
    designation VARCHAR(100),
    hire_date DATE,
    employment_status VARCHAR(30),
    salary DECIMAL(12,2),
    city VARCHAR(100),

    FOREIGN KEY (department_id)
    REFERENCES departments(department_id)
);

The employee_id uniquely identifies each employee. The department_id column connects employees to their respective departments.

Notice that department_id is a foreign key rather than a primary key in this table.

This relationship allows multiple employees to belong to the same department.

Table 3: Clients

The clients table stores information about individuals and organisations that purchase construction, interior decoration or architecture consulting services.

CREATE TABLE clients (
    client_id INT AUTO_INCREMENT PRIMARY KEY,
    client_name VARCHAR(150) NOT NULL,
    client_type VARCHAR(50),
    contact_person VARCHAR(150),
    email VARCHAR(150),
    phone VARCHAR(20),
    address TEXT,
    city VARCHAR(100),
    state VARCHAR(100),
    country VARCHAR(100),
    registration_date DATE
);

The client_id identifies each client uniquely.

Other columns store client contact information, business type and geographical details.

This table will help us analyse client distribution, client relationships and project activity.

Table 4: Service Types

A construction company may offer different services. Instead of repeatedly entering service names in the projects table, we maintain a separate service_types table.

CREATE TABLE service_types (
    service_type_id INT AUTO_INCREMENT PRIMARY KEY,
    service_name VARCHAR(100) NOT NULL,
    description TEXT
);

Our project includes three main services:

  • Construction
  • Interior Decoration
  • Architecture Consulting

Each service receives a unique service_type_id.

Table 5: Projects

The projects table is one of the most important tables in our database.

It stores information about construction and consulting projects undertaken by the company.

CREATE TABLE projects (
    project_id INT AUTO_INCREMENT PRIMARY KEY,
    project_name VARCHAR(200) NOT NULL,
    client_id INT NOT NULL,
    service_type_id INT NOT NULL,
    project_manager_id INT,
    project_location VARCHAR(200),
    start_date DATE,
    expected_end_date DATE,
    actual_end_date DATE,
    estimated_budget DECIMAL(15,2),
    actual_cost DECIMAL(15,2),
    project_status VARCHAR(50),
    priority VARCHAR(30),

    FOREIGN KEY (client_id)
    REFERENCES clients(client_id),

    FOREIGN KEY (service_type_id)
    REFERENCES service_types(service_type_id),

    FOREIGN KEY (project_manager_id)
    REFERENCES employees(employee_id)
);

Each project belongs to a particular client and service category.

The project_manager_id connects the project to the employee responsible for managing it.

The estimated_budget and actual_cost columns are particularly useful for financial analysis.

We can use them to investigate project budgets, cost variations and financial performance.

Table 6: Project Assignments

A construction project generally requires multiple employees. Similarly, an employee may work on several projects.

This creates a many-to-many relationship between employees and projects.

To manage this relationship, we create a separate project_assignments table.

CREATE TABLE project_assignments (
    assignment_id INT AUTO_INCREMENT PRIMARY KEY,
    project_id INT NOT NULL,
    employee_id INT NOT NULL,
    assigned_date DATE,
    role_in_project VARCHAR(100),
    allocation_percentage DECIMAL(5,2),

    FOREIGN KEY (project_id)
    REFERENCES projects(project_id),

    FOREIGN KEY (employee_id)
    REFERENCES employees(employee_id),

    UNIQUE (project_id, employee_id)
);

This table records which employee is assigned to which project.

It also stores the employee’s role and percentage of allocation.

The combination of project_id and employee_id is unique, preventing duplicate assignments of the same employee to the same project.

Table 7: Quotations

Before starting a construction project, companies generally prepare quotations for their clients.

A quotation contains estimated costs, taxes, discounts and the final proposed amount.

CREATE TABLE quotations (
    quotation_id INT AUTO_INCREMENT PRIMARY KEY,
    quotation_number VARCHAR(50) UNIQUE NOT NULL,
    client_id INT NOT NULL,
    project_id INT,
    prepared_by INT,
    quotation_date DATE,
    valid_until DATE,
    subtotal DECIMAL(15,2),
    tax_amount DECIMAL(15,2),
    discount_amount DECIMAL(15,2),
    total_amount DECIMAL(15,2),
    quotation_status VARCHAR(50),

    FOREIGN KEY (client_id)
    REFERENCES clients(client_id),

    FOREIGN KEY (project_id)
    REFERENCES projects(project_id),

    FOREIGN KEY (prepared_by)
    REFERENCES employees(employee_id)
);

The quotation_id uniquely identifies each quotation.

The client_id identifies the client receiving the quotation, while project_id connects it to the relevant project when applicable.

The quotation_status field can contain values such as Accepted, Rejected, Pending, Expired and Revised.

This table will be useful for analysing quotation values and approval rates.

Table 8: Quotation Items

A quotation may contain several individual items, including construction materials, labour, electrical installation, plumbing, flooring and design services.

Instead of storing all these items in a single quotation record, we maintain a separate quotation_items table.

CREATE TABLE quotation_items (
    item_id INT AUTO_INCREMENT PRIMARY KEY,
    quotation_id INT NOT NULL,
    item_description VARCHAR(255),
    quantity DECIMAL(12,2),
    unit VARCHAR(50),
    unit_price DECIMAL(15,2),
    total_price DECIMAL(15,2),

    FOREIGN KEY (quotation_id)
    REFERENCES quotations(quotation_id)
);

The quotation_id connects each item to its parent quotation.

For example, one quotation may contain five different items, resulting in five records in the quotation_items table.

This structure allows us to analyse item-wise pricing, quantities and quotation composition.

Table 9: Project Payments

The project_payments table records payments received from clients against their projects.

CREATE TABLE project_payments (
    payment_id INT AUTO_INCREMENT PRIMARY KEY,
    project_id INT NOT NULL,
    client_id INT NOT NULL,
    payment_date DATE,
    payment_amount DECIMAL(15,2),
    payment_method VARCHAR(50),
    payment_status VARCHAR(50),
    transaction_reference VARCHAR(100),

    FOREIGN KEY (project_id)
    REFERENCES projects(project_id),

    FOREIGN KEY (client_id)
    REFERENCES clients(client_id)
);

This table helps the company maintain payment records and monitor collections.

The payment_method column stores payment methods such as Bank Transfer, Check, ACH and Credit Card.

The payment_status column can identify Completed, Pending and Failed transactions.

Table 10: Project Expenses

The final table records expenses incurred during project execution.

Construction projects involve several expenditure categories, including materials, labour, equipment rental, transportation, permits and professional services.

CREATE TABLE project_expenses (
    expense_id INT AUTO_INCREMENT PRIMARY KEY,
    project_id INT NOT NULL,
    expense_category VARCHAR(100),
    expense_description TEXT,
    expense_date DATE,
    amount DECIMAL(15,2),
    vendor_name VARCHAR(150),
    payment_status VARCHAR(50),

    FOREIGN KEY (project_id)
    REFERENCES projects(project_id)
);

Each expense is associated with a particular project.

This table will help us analyse project-wise expenditure, expense categories, vendor activity and outstanding payments.

3. Understanding Primary Keys and Foreign Keys

While creating relational databases, two important concepts are primary keys and foreign keys.

A primary key uniquely identifies each record in a table. For example, employee_id identifies an employee, client_id identifies a client and project_id identifies a project.

A foreign key establishes a relationship between two tables.

For example, the department_id column in the employees table references department_id in the departments table.

This ensures that an employee can be associated with an existing department.

Similarly, the projects table contains three important foreign keys:

  • client_id references the clients table.
  • service_type_id references the service_types table.
  • project_manager_id references the employees table.

These relationships allow us to combine information from multiple tables using SQL JOIN operations.

4. Understanding Database Relationships

Our Construction ERP database uses three important types of relationships.

One-to-Many Relationship

A one-to-many relationship means one record in a table can be associated with multiple records in another table.

For example, one department can have multiple employees.

Similarly, one client can have multiple projects, and one project can have multiple expenses.

Many-to-Many Relationship

A many-to-many relationship exists when multiple records in one table can be associated with multiple records in another table.

In our database, employees can work on multiple projects, and each project can have multiple employees.

We manage this relationship through the project_assignments junction table.

One-to-One Relationship

A one-to-one relationship means one record in a table corresponds to only one record in another table.

Our current database design does not implement a dedicated one-to-one relationship. The primary focus is on one-to-many and many-to-many relationships.

5. Database Analysis and Power BI Integration

Once all ten tables are created and populated with sample records, we can start exploring the database using SQL queries.

For example, we can calculate the total number of projects, identify the most active clients, analyse department-wise employee distribution and investigate project expenditure.

The same database can also be connected to Microsoft Power BI for Exploratory Data Analysis.

We can build dashboards around clients, projects, employees, quotations, payments and expenses.

During this process, we can also create SQL Views to prepare business-friendly analytical datasets without modifying the original ERP tables.

A SQL View stores a query definition rather than a separate copy of the underlying records. This makes views useful for simplifying JOIN operations and preparing reporting layers.

For more advanced Power BI modelling, we can use these views to create a Star Schema with fact and dimension tables.

Conclusion

Building a Construction ERP database is a practical way to understand how relational databases work in real business environments.

In this project, we have created ten interconnected tables covering employees, departments, clients, projects, quotations, payments and expenses.

We have also explored primary keys, foreign keys, one-to-many relationships and many-to-many relationships.

The purpose is not simply to create tables but to develop a structured business dataset that can support meaningful analysis.

As we move forward, we will use SQL queries, analytical views and Microsoft Power BI to explore business performance, identify trends and create interactive dashboards.

I believe that working with a complete business database provides a much better learning experience than practising SQL on isolated tables because it demonstrates how information flows across different departments and business operations.