Dbms Ia 1 Set B Scheme
Dbms Ia 1 Set B Scheme
USN
Degree : B.E Semester : III
Branch : CS & BS Course Code : BCS 403
Course Title : Database Management Systems Date : 30/05/2024
Duration : 90 Minutes Max Marks : 30
2M
1 (a) 5
3M
➢ Casual users interact with the interactive query interface. The queries are
parsed and validated for correctness of the query syntax, the names of
files and data elements by a query compiler. This internal query is
subjected to query optimization. The query optimizer is concerned with
the ordering of operations, elimination of redundancies, and use of correct
algorithms and indexes during execution.
➢ The query optimizer consults the system catalog for statistical and other
physical information about the stored data and generates executable code
that performs the necessary operations for the query and makes calls on
the runtime processor
1M
2M
C) 5
➢ Logical data independence refers to the ability to change the conceptual
schema (logical schema) of the database without affecting the external
schema or application programs.Changes to the logical schema involve
modifications to the way data is organized, modeled, or represented at the
conceptual level, such as adding, modifying, or dropping tables, columns,
or relationships.
➢ Application programs accessing the data through the external schema are
shielded from these changes, as they interact with the data through a
conceptual view of the database.Logical data independence allows for
modifications to the database design, such as normalization,
denormalization, or restructuring, without impacting the applications that
use the data.
Example: 1M
1M
i) Database:
➢ A database is a structured collection of data organized and stored
electronically in a computer system. It typically consists of tables
(relations) that store data in rows and columns, along with relationships
between tables. Databases are designed to efficiently manage, retrieve,
and manipulate data to meet the needs of users and applications.
(b) 5
Generalization
We can have three sub entities as Car, Truck, Motorcycle and these three entities
can be generalized into one general super class as Vehicle.
Aggregation
2M
➢ Outer join operations in relational algebra are used to combine tuples
from two relations even if there is no matching tuple in one of the
relations. There are three types of outer joins: left outer join, right outer
join, and full outer join.
Students (sid, name):
| sid | name |
(b) |-----|--------| 5
| 101 | Alice |
| 102 | Bob |
| 103 | Charlie|
Grades (sid, grade):
| sid | grade |
|-----|-------|
| 101 | A |
| 103 | B |
| 104 | C |
Left Outer Join: 1M
➢ A left outer join returns all tuples from the left relation (Students) and
matching tuples from the right relation (Grades). If there is no matching
tuple in the right relation, NULL values are used.
Students ⋈ᴸ Grades
Applying left outer join to the given example:
| sid | name | grade |
|-----|---------|-------|
| 101 | Alice | A |
| 102 | Bob | NULL |
| 103 | Charlie | B |
Right Outer Join: 1M
➢ A right outer join returns all tuples from the right relation (Grades) and
matching tuples from the left relation (Students). If there is no matching
tuple in the left relation, NULL values are used.
Students ⋈ᴿ Grades
Applying right outer join to the given example:
| sid | name | grade |
|-----|---------|-------|
| 101 | Alice | A |
| 103 | Charlie | B |
| 104 | NULL |C |
Full Outer Join: 1M
➢ A full outer join returns all tuples from both relations. If there is no
matching tuple in one of the relations, NULL values are used for the
attributes from that relation.
Students ⋈ᶠ Grades
Applying full outer join to the given example:
| sid | name | grade |
|-----|---------|-------|
| 101 | Alice | A |
| 102 | Bob | NULL |
| 103 | Charlie | B |
| 104 | NULL |C |
These examples illustrate how left, right, and full outer joins combine tuples from
two relations, considering matching tuples and handling cases where there is no
match.
1M
i) For all customers who have a loan from the bank, find their names, loan
numbers, and loan amount.
SELECT c.customer_name, l.loan_number, l.amount
FROM customer c
INNER JOIN borrower b ON c.customer_name = b.customer_name
INNER JOIN loan l ON b.loan_number = l.loan_number;
1M
ii) Find the customer names, loan numbers, and loan amounts, for all loans at the
Perry ridge branch.
SELECT c.customer_name, l.loan_number, l.amount
FROM customer c
INNER JOIN borrower b ON c.customer_name = b.customer_name
C) INNER JOIN loan l ON b.loan_number = l.loan_number
WHERE l.branch_name = 'Perry ridge';
1M
iii) Find the names of all branches that have assets greater than those of at least
one branch located in Brooklyn.
SELECT DISTINCT b1.branch_name
FROM branch b1
WHERE b1.assets > ANY (SELECT b2.assets FROM branch b2 WHERE
b2.branch_city = 'Brooklyn');
1M
iv) Find the average account balance of those branches where the account balance
is greater than Rs. 1200.
SELECT branch_name, AVG(balance) AS avg_balance
FROM account
GROUP BY branch_name
HAVING AVG(balance) > 1200;
1M
v) Find the maximum across all branches of the total balance at each branch.
SELECT branch_name, SUM(balance) AS total_balance
FROM account
GROUP BY branch_name
ORDER BY total_balance DESC
LIMIT 1;
Administrative Users: 2M
➢ These users are responsible for managing the overall database system,
including installation, configuration, security, and performance tuning.
Interface: Administrative users typically interact with the DBMS through
specialized tools or command-line interfaces designed for system
administration tasks. These interfaces provide features for managing users,
configuring database settings, monitoring performance, and performing
backup and recovery operations.
Database Designers:
➢ End users are the consumers of the data stored in the database. They may
include business analysts, report writers, and other non-technical users
who need access to the database for querying and reporting purposes.
Interface: End users typically interact with the database through front-end
applications or reporting tools that provide user-friendly interfaces for executing
predefined queries, generating reports, and visualizing data. These interfaces
abstract the complexity of SQL queries and database structures, allowing end
users to access and analyze data without requiring deep technical knowledge.
➢ Each category of database users has specific roles and responsibilities,
and their interfaces to the DBMS are tailored to support their respective
tasks and requirements.
➢ Cardinality ratio specifies the number of instances of one entity that can
be associated with a single instance of another entity in a relationship.
Example: In our library database, the cardinality ratio between "Book" and
"Copy" is one-to-many because one book can have multiple copies, but each
copy belongs to only one book.
(iv) Recursive Relationship:
1M
➢ A recursive relationship occurs when an entity is related to itself through
a relationship set.
Example: In our library database, we can have a recursive relationship between
"Borrower" and "Borrower" to represent borrowers who recommend books to
other borrowers. For example, we could have a relationship "Recommends" with
attributes like "recommendation_id", "borrower_id",
"recommended_to_borrower_id", and "recommendation_date".
(v) Specialization: 1M
(i) Retrieve the name, address, salary of employees who work for the
Research department. 1M
(iii) Retrieve the SSN of all employees who are either in department number 4 or
directly supervise an employee who works in department number 4. 1M
FROM EMP
WHERE EMP.Dno = 4
OR EMP.SSN IN (
SELECT DISTINCT EMP1.SuperSSN
FROM EMP AS EMP1
INNER JOIN EMP AS EMP2 ON EMP1.SSN = EMP2.SuperSSN
WHERE EMP2.Dno = 4
);
FROM EMP
WHERE EMP.SSN NOT IN (
SELECT ESSN
FROM DEPENDENT
);(v) Retrieve each department number, the number of employees in the
department, and their average salary.
1M
SELECT DEPT.Dnum, COUNT(EMP.SSN) AS NumEmployees,
AVG(EMP.Salary) AS AvgSalary
FROM DEPT
INNER JOIN EMP ON DEPT.Dnum = EMP.Dno
GROUP BY DEPT.Dnum;