Employee and Salary Table Structure and Data Guidelines
1.employee Table:
id: NUMBER ;— primary key, unique identifier of each employee.
empname: VARCHAR2(20); — name of the employee cannot be null.
birth_date: DATE ;— birthdate of the employee cannot be null.
mgr_id: NUMBER ;— foreign key referencing the id of another employee which sets up self-referential relationship of managers.
2.salary Table:
id: NUMBER; — Foreign key referencing the id from the table employee linking each record to a particular employee.
designation: VARCHAR2(25) ;— Employee designation or designation non-nullable.
salary: NUMBER ;— Salary of the employee.
Summary of Relationship
•Employee has self-referential foreign key (mgr_id) that is to be used in order to present managers.
• The table salary has a foreign key id, which points to the employee table that links the salary data with the respective employees.
Creating table
1.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)
);
Description
The employee table stores some basic information about every employee in the organization.
These columns are:
id: Unique identifier for a particular employee (primary key).
empname: The name of the employee which cannot be NULL.
birth_date: The birth date of the employee stored as a date also non-nullable.
mgr_id: Self-referencing foreign key that links an employee with his manager if any. It references id of other employee in same table in order to set a chain of managers and subordinates.