0% found this document useful (0 votes)
11 views

RDBMS Query 4 (1)

The document outlines the creation of a COMPANY database with three tables: EMPLOYEE, DEPART, and PROJECT, including necessary constraints. It provides SQL commands for inserting sample data, performing various queries such as deleting departments with fewer than one employee, displaying female employees, and updating salaries. Additionally, it includes commands for counting employees in specific departments and listing employees based on experience criteria.

Uploaded by

aparnac239
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

RDBMS Query 4 (1)

The document outlines the creation of a COMPANY database with three tables: EMPLOYEE, DEPART, and PROJECT, including necessary constraints. It provides SQL commands for inserting sample data, performing various queries such as deleting departments with fewer than one employee, displaying female employees, and updating salaries. Additionally, it includes commands for counting employees in specific departments and listing employees based on experience criteria.

Uploaded by

aparnac239
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Query 4

Create the database COMPANY and create given tables with all necessary constraints such
asprimary key, foreign key, unique key, not null and check constraints.

EMPLOYEE (emp_id, emp_name, birth_date, gender, dept_no, address, designation, salary,


experience, email)

DEPART (dept_no, dept_name, total_employees, location)

PROJECT (proj_id, type_of_project, status, start_date, emp_id)

Insert proper data (at least 5 appropriate records) in all the tables.

1. Delete the department whose total number of employees less than 1.


2. Display the names and the designation of all female employee in descending order.

3. Display the names of all the employees who names starts with ‘A’ ends with ‘A’.

4. Find the name of employee and salary for those who had obtain minimum salary.

5. Add 10% raise in salary of all employees whose department is ‘CIVIL’.

6. Count total number of employees of ‘MCA’ department.

7. List all employees who born in the current month.

8. Print the record of employee and dept table as “Employee works in department ‘CE’.

9. List names of employees who are fresher’s(less than 1 year of experience).

10. List department wise names of employees who has more than 5 years of experience

Solution:

CREATE TABLE EMPLOYEE (

emp_id INT PRIMARY KEY,

emp_name VARCHAR2(50) NOT NULL,

birth_date DATE NOT NULL,

gender VARCHAR2(10) CHECK (gender IN ('Male', 'Female')),

dept_no INT,

address VARCHAR2(100),

designation VARCHAR2(50),
salary NUMBER(10,2),

experience INT,

email VARCHAR2(100),

CONSTRAINT emp_dept_fk FOREIGN KEY (dept_no) REFERENCES DEPART(dept_no)

);

CREATE TABLE DEPART (

dept_no INT PRIMARY KEY,

dept_name VARCHAR2(50) NOT NULL,


total_employees INT CHECK (total_employees >= 0),

location VARCHAR2(100)

);

CREATE TABLE PROJECT (

proj_id INT PRIMARY KEY,

type_of_project VARCHAR2(50),

status VARCHAR2(50),

start_date DATE,

emp_id INT,

CONSTRAINT proj_emp_fk FOREIGN KEY (emp_id) REFERENCES


EMPLOYEE(emp_id)

);

INSERT INTO EMPLOYEE VALUES (1, 'John Doe', TO_DATE('1990-05-15', 'YYYY-MM-


DD'), 'Male', 1, '123 Main St', 'Manager', 50000, 5, '[email protected]');

INSERT INTO EMPLOYEE VALUES (2, 'Jane Smith', TO_DATE('1995-10-20', 'YYYY-MM-


DD'), 'Female', 2, '456 Oak St', 'Engineer', 40000, 3, '[email protected]');
INSERT INTO EMPLOYEE VALUES (3, 'Alice Johnson', TO_DATE('1992-03-01', 'YYYY-
MM-DD'), 'Female', 1, '789 Elm St', 'Analyst', 45000, 2, '[email protected]');

INSERT INTO EMPLOYEE VALUES (4, 'Bob Brown', TO_DATE('1988-12-10', 'YYYY-MM-


DD'), 'Male', 2, '101 Pine St', 'Developer', 55000, 6, '[email protected]');

INSERT INTO EMPLOYEE VALUES (5, 'Ella Garcia', TO_DATE('1998-08-05', 'YYYY-MM-


DD'), 'Female', 1, '202 Cedar St', 'Designer', 38000, 1, '[email protected]');

INSERT INTO DEPART VALUES (1, 'IT', 3, 'New York');

INSERT INTO DEPART VALUES (2, 'HR', 2, 'Los Angeles');

INSERT INTO PROJECT VALUES (1, 'Software Development', 'In Progress',


TO_DATE('2024-01-10', 'YYYY-MM-DD'), 1);

INSERT INTO PROJECT VALUES (2, 'Marketing Campaign', 'Completed', TO_DATE('2023-


05-20', 'YYYY-MM-DD'), 2);

Delete the department whose total number of employees less than 1:

DELETE FROM DEPART WHERE total_employees < 1;

Display the names and the designation of all female employees in descending order:

SELECT emp_name, designation FROM EMPLOYEE WHERE gender = 'Female' ORDER BY


emp_name DESC;

Display the names of all the employees whose names start with ‘A’ and end with ‘A’:

SELECT emp_name FROM EMPLOYEE WHERE emp_name LIKE 'A%A';

Find the name of the employee and salary for those who had obtained the minimum salary

SELECT emp_name, salary FROM EMPLOYEE WHERE salary = (SELECT MIN (salary)
FROM EMPLOYEE);
Add a 10% raise in salary for all employees whose department is ‘CIVIL’

UPDATE EMPLOYEE SET salary = salary * 1.1 WHERE dept_no = (SELECT dept_no FROM
DEPART WHERE dept_name = 'CIVIL');

Count the total number of employees in the ‘MCA’ department

SELECT COUNT(*) FROM EMPLOYEE WHERE dept_no = (SELECT dept_no FROM


DEPART WHERE dept_name = 'MCA');

List the names of employees who are fresher’s (less than 1 year of experience)

SELECT emp_name FROM EMPLOYEE WHERE experience < 1;

List department-wise names of employees who have more than 5 years of experience

SELECT emp_name, dept_name FROM EMPLOYEE e JOIN DEPART d ON e.dept_no =


d.dept_no WHERE experience > 5;

You might also like