Employee and Salary Table Structure in SQL
Designing an Employee and Salary table structure is one of the most
common tasks in SQL interviews and real-world HR/payroll systems. In this tutorial,
you'll learn the schema, relationships, and CREATE TABLE scripts needed
to build a clean employee–salary database in Oracle SQL, and then
practice with interview queries
built on these same tables.
1. Schema Overview
We use two related tables: employee stores identity and reporting
information, while salary stores compensation details. Both tables
are linked via the shared id column.
employee Table
id— NUMBER, primary key, unique identifier for each employee.empname— VARCHAR2(20), employee name (NOT NULL).birth_date— DATE, employee's birth date (NOT NULL).mgr_id— NUMBER, self-referencing foreign key toemployee(id)for manager relationships.
salary Table
id— NUMBER, foreign key toemployee(id).designation— VARCHAR2(25), job title (NOT NULL).salary— NUMBER, monthly/base salary amount.
Relationship Summary
- The
employeetable has a self-referential foreign key (mgr_id) to represent manager–subordinate chains. - The
salarytable has a foreign keyidpointing toemployee, linking compensation to each employee.