2. CREATE TABLE Scripts

Employee Table

CREATE TABLE employee (
    id          NUMBER PRIMARY KEY,
    empname     VARCHAR2(20) NOT NULL,
    birth_date  DATE NOT NULL,
    mgr_id      NUMBER REFERENCES employee(id)
);

The employee table stores core identity information. The mgr_id column creates a self-referencing link so each employee can point to their manager within the same table.

Salary Table

CREATE TABLE salary (
    id           NUMBER REFERENCES employee(id),
    designation  VARCHAR2(25) NOT NULL,
    salary       NUMBER
);

The salary table stores designation and salary details. Its id column is a foreign key to employee(id), ensuring every salary record maps to a valid employee.

Employee and Salary table structure diagram in SQL

3. Sample Data

Employee Table (sample rows)

idempnamebirth_datemgr_id
1Amit Sharma1985-04-25NULL
2John Smith1990-02-151
3Priya Desai1980-08-301
4Robert Johnson1995-11-052
5Suresh Kumar1992-06-183

Salary Table (sample rows)

iddesignationsalary
1Senior Developer120000
2Software Engineer80000
3Project Manager150000
4Junior Developer60000
5Team Lead110000

With these two tables in place, you can start writing real queries. See Top Queries on Employee Salary Management for the full set.

4. Frequently Asked Questions

Why is mgr_id a self-referencing foreign key?

It allows an employee row to reference another row in the same table, modelling the manager–subordinate hierarchy without a separate table.

Can one employee have multiple salary records?

Yes — you can allow multiple rows per id to track salary revisions over time, or add a PRIMARY KEY on (id, effective_date).

What is the primary key of the salary table?

In this basic design, id is only a foreign key. For production, consider adding a surrogate primary key or a composite key.

What SQL operations can I perform on these tables?

Common operations include: SELECT with JOIN to combine employee and salary data, aggregate functions like SUM and AVG for salary reporting, and self-joins to display manager–subordinate relationships.