0% found this document useful (0 votes)
1 views31 pages

DBMS Assignment

Dbms question

Uploaded by

kishankhaniya477
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views31 pages

DBMS Assignment

Dbms question

Uploaded by

kishankhaniya477
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Assignment No.

– 1

Q1. Create the following table “Employees”

Column Name Datatype Size

Emp_id (Primary Key) Number 10

Emp_name Varchar2 20

Dept_id Number 20

Q2. Insert the following data in the Employees table

Emp_id Emp_name Dept_id

1 Alice 10

2 Bob 20

3 Charlie 30

4 David NULL

5 Emma 10

6 Frank 20

7 Grace 30

8 Hannah 30
Q3. Create the following table “Departments”

Column Name Datatype Size

Dept_id (Primary Key) Number 10

Dept_name Varchar2 10

Q4. Insert the following data in the Departments table

Dept_id Dept_name

10 HR

20 IT

40 Marketing

30 Finance

50 Operations

60 Research

70 Legal

80 Sales
OBJECTIVE :

Q1. Create Employees Table.

Ans -
Output

Q2. Create Departments Table.

Ans -
Output

Q5. Based on above two tables answer the following Questionaries: -

I). Use an INNER JOIN to find the names of employees who belong to a department.
Ans:

Output
II). Use a LEFT OUTER JOIN to list all employees, showing their department if they have one. If
an employee does not belong to a department, show NULL for the department name.
Ans:

Output

III). Use a RIGHT OUTER JOIN to list all departments, showing the names of employees in each
department. If a department has no employees, show NULL for the employee’s name.
Ans:
Output

IV). Use a FULL OUTER JOIN to list all employees and all departments, showing NULL for
departments with no employees and employees with no department.
Ans:
Output

V). Use an INNER JOIN to find the names of employees who are in both IT and HR departments.
Ans:
Output

VI). Write a query to find employees without a department using a LEFT JOIN.
Ans:

Output
VII). Find the total number of employees in each department using INNER JOIN and
GROUP BY.
Ans:

Output

VIII). Find all employees who do not belong to either the “HR” or “IT” department using an
OUTER JOIN.
Ans:
Output

XI). List the names of employees and departments where employees work, but exclude records
where department names start with the letter "M."
Ans:

Output
X). Use a LEFT JOIN to list all employees and count how many employees are in each department,
even if some departments have no employees.
Ans:

Output

XI). Find the department name and employee name for employees who have no department
assigned by using an OUTER JOIN.
Ans:

Output
XII). Write a query to find employees who are in the same department as another employee.
(This query uses a Self Join to find pairs of employees in the same department.)
Ans:

Output
Assignment – 2
OBJECTIVES:

Q1. Create the Employees Table.


Ans:
Output

Q2. Create Departments Table.


Ans:
Output

Q5. Based on above two tables answer the following Questionaries: -


I). Display all employee names in uppercase along with their salaries.
Ans:

Output
II). Retrieve the total number of employees.
Ans:

Output

III). Calculate the average salary of all employees.


Ans:

Output

IV). Count the number of employees in each department.


Ans:
Output

V). Calculate the total salary paid in each department.


Ans:

Output

VI). Display the length of each employee's name.


Ans:
Output

VII). Display the first three characters of each employee's name.


Ans:

Output
VIII). List all employees who joined after January 1, 2020.
Ans:

Output

IX). Find the department name and total salary paid in that department using LEFT
JOIN.
Ans:
Output

X). Calculate the total salary paid to employees, rounded to two decimal places.
Ans:

Output
Assignment - 3
Q1. Create the following table “Employees_2023”

Column Name Datatype Size

emp_id (PRIMARY KEY) NUMBER 10

emp_name VARCHAR2 20

dept_id NUMBER 10

Q2. Insert the following data in the Employees_2023 table

emp_id emp_name dept_id

1 Alice 10

2 Bob 20

3 Charlie 30

4 David 40

Q3. Create the following table “Employees_2024”

Column Name Datatype Size

emp_id (PRIMARY KEY) NUMBER 10

emp_name VARCHAR2 20

dept_id NUMBER 10
Q4. Insert the following data in the Employees_2024 table

emp_id emp_name dept_id

2 Bob 20

3 Charlie 30

5 Eve 50

6 Frank 60

OBJECTIVE:
Q1. Create Table Employees_2023.
Ans:

Output

Q1. Create Table Employees_2024.


Ans:
Output

Q5. Based on above two tables answer the following Questionaries: -

I). Find all unique employees from both tables.


Ans:

Output

II). Find employees common to both tables.


Ans:
Output

III). Find employees who are in Employees_2023 but not in Employees_2024.


Ans:

Output

IV). List employees who belong to department 20 from either table.


Ans:
Output

V). Find employees in department 10 who are not in Employees_2024.


Ans:

Output

VI). List all employees sorted by emp_id.


Ans:
Output

VII). Find employees who are only in one table but not both.
Ans:

Output
VIII).Find employees whose emp_id is greater than 3 from both tables.
Ans:

Output

IX). Find employees who are in Employees_2023 but not in Employees_2024, and sort them by
dept_id.
Ans:

Output
X). Retrieve all employees from both tables, including duplicates.
Ans:

Output

You might also like