Model dbms-1
Model dbms-1
AIM:
To create the database using the relational schema
EMPLOYEE ( Emp_id, First_name, Last_name, Salary, Joining_date, Dept_id )
DEPARTMENT ( Dept_id, Dept_name, Dept_incharge )
INCENTIVES ( Emp_id, Incentive_date, Incentive_amount )
PROCEDURE:
CREATE TABLE DEPARTMENT (
Dept_id INT PRIMARY KEY,
Dept_name VARCHAR(255),
Dept_incharge VARCHAR(255)
);
CREATE TABLE EMPLOYEE (
Emp_id INT PRIMARY KEY,
First_name VARCHAR(255),
Last_name VARCHAR(255),
Salary DECIMAL(10, 2),
Joining_date DATE,
Dept_id INT,
FOREIGN KEY (Dept_id) REFERENCES DEPARTMENT(Dept_id)
);
3. Get Employee ID's of those employees who didn't receive incentives without using sub query.
SELECT e.Emp_id
FROM EMPLOYEE e
LEFT JOIN INCENTIVES i ON e.Emp_id = i.Emp_id
WHERE i.Emp_id IS NULL;
4. Update the incentives of 'Your Name' to 20,000.
UPDATE INCENTIVES
SET Incentive_amount = 20000
WHERE Emp_id = '1';
SELECT * FROM INCENTIVES;
5. List the employees who are from the same department as ‘Alice’.
SELECT e.First_name, e.Last_name
FROM EMPLOYEE e
JOIN EMPLOYEE a ON e.Dept_id = a.Dept_id
WHERE a.First_name = 'Alice';