HR & Employee Database Schema

A human-resources model for tracking an organization. Employees belong to a department and hold a position, report to a manager through a self-referencing link, accrue a salary history over time, and submit leave requests. It is a clean base for an HRMS, payroll, or org-chart tool.

Open in editor → 5 tables · MySQL DDL

Tables in this schema

departmentspositionsemployeessalariesleave_requests

Schema (SQL)

MySQL-dialect DDL. Open it in the editor for a visual ER diagram you can edit, or copy the SQL straight into your project.

CREATE TABLE departments (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL UNIQUE,
  cost_center VARCHAR(20)
);

CREATE TABLE positions (
  id INT PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(100) NOT NULL,
  level VARCHAR(20) NOT NULL
);

CREATE TABLE employees (
  id INT PRIMARY KEY AUTO_INCREMENT,
  department_id INT NOT NULL,
  position_id INT NOT NULL,
  manager_id INT,
  full_name VARCHAR(120) NOT NULL,
  email VARCHAR(254) NOT NULL UNIQUE,
  hired_at DATE NOT NULL,
  FOREIGN KEY (department_id) REFERENCES departments(id),
  FOREIGN KEY (position_id) REFERENCES positions(id),
  FOREIGN KEY (manager_id) REFERENCES employees(id)
);

CREATE TABLE salaries (
  id INT PRIMARY KEY AUTO_INCREMENT,
  employee_id INT NOT NULL,
  amount DECIMAL(12,2) NOT NULL,
  currency VARCHAR(3) NOT NULL,
  effective_from DATE NOT NULL,
  FOREIGN KEY (employee_id) REFERENCES employees(id)
);

CREATE TABLE leave_requests (
  id INT PRIMARY KEY AUTO_INCREMENT,
  employee_id INT NOT NULL,
  start_date DATE NOT NULL,
  end_date DATE NOT NULL,
  type VARCHAR(30) NOT NULL,
  status VARCHAR(20) NOT NULL,
  FOREIGN KEY (employee_id) REFERENCES employees(id)
);