Assignment 1 DBMS Solution
Assignment 1 DBMS Solution
Solution: A super key is a set of attributes within a relation that uniquely identifies each tuple. A super key
may contain additional attributes that are not strictly necessary for uniqueness.
A candidate key is a set of attributes within a relation (table) that uniquely identifies each tuple (row) in that
relation. It means that no two distinct tuples can have the same values for all the attributes in the candidate
key. A relation may have multiple candidate keys. Among the candidate keys, one is selected as the primary
key.
The primary key is one of the candidate keys chosen to uniquely identify each tuple in the relation. It is
designated as the main key for the relation and is used to enforce entity integrity. The primary key attribute(s)
must be unique and not null.
Q.8 Draw ER diagram for university database consisting of four entities Student,
Department, Class, and Faculty. Student has a unique id, the student can enrol for
multiple classes and has a most one major. Faculty must belong to department and
faculty can teach multiple classes. Each class is taught by only faculty. Every student will
get grade for the class he/she has enrolled.
Solution: Student entity has attributes like StudentID (primary key), Name, and MajorID (foreign key
referencing Major table).
Department entity has attributes like DeptID (primary key) and DeptName.
Class entity has attributes like ClassID (primary key), ClassName, DeptID (foreign key referencing
Department table), and FacultyID (foreign key referencing Faculty table).
Faculty entity has attributes like FacultyID (primary key), Name, and DeptID (foreign key referencing
Department table).
Enroll entity is a junction table representing the many-to-many relationship between Student and Class. It
contains attributes like StudentID (foreign key referencing Student table), ClassID (foreign key referencing
Class table), and Grade.
Q.9 Consider the BANK ER schema in Figure 7.21 and suppose that it is necessary to keep track of different
types of ACCOUNTS (SAVINGS_ACCTS, CHECKING_ACCTS, ...) and LOANS (CAR_LOANS,
HOME_LOANS, ...). Suppose that it is also desirable to keep track of each ACCOUNT’s TRANSACTIONS
(deposits, withdrawals, checks, ...) and each LOAN’s PAYMENTS; both include the amount, date, and time.
Modify the BANK schema, using ER and EER concepts of specialization and generalization. State any
assumptions you make about the additional.
Solution:
To modify the BANK schema to incorporate different types of accounts (e.g., savings accounts, checking
accounts) and loans (e.g., car loans, home loans), along with tracking transactions and payments, we can use
the concepts of specialization and generalization in the Enhanced Entity-Relationship (EER) model. Below is
the modified schema:
+------------+
| ENTITY |
+------------+
| EntityID |
+------------+
|
|
|
+-------------------------+
| ACCOUNT |
+-------------------------+
| AccountID |
| Balance |
| AccountType |
+-------------------------+
/ \
/ \
/ \
+---------------------------+ +-----------------------------+
| SAVINGS_ACCT | | CHECKING_ACCT |
+---------------------------+ +-----------------------------+
| InterestRate | | OverdraftLimit |
+---------------------------+ +-----------------------------+
|
|
|
+------------------+
| TRANSACTION |
+------------------+
| TransactionID |
| Amount |
| Date |
| Time |
+------------------+
|
|
|
+------------------+
| LOAN |
+------------------+
| LoanID |
| Amount |
| LoanType |
+------------------+
|
|
|
+-------------------+
| PAYMENT |
+-------------------+
| PaymentID |
| Amount |
| Date |
| Time |
+-------------------+
Explanation:
• ENTITY: This represents the base entity for all entities in the schema. It includes common attributes
shared by all entities, such as EntityID.
• ACCOUNT: This entity represents accounts in the bank. It includes attributes like AccountID
(primary key), Balance, and AccountType to differentiate between savings accounts, checking
accounts, etc.
• SAVINGS_ACCT and CHECKING_ACCT: These are specialization entities of the ACCOUNT
entity. They inherit attributes from the ACCOUNT entity and include additional attributes specific to
each account type.
• TRANSACTION: This entity tracks transactions related to accounts. It includes attributes like
TransactionID, Amount, Date, and Time.
• LOAN: This entity represents loans in the bank. It includes attributes like LoanID, Amount, and
LoanType to differentiate between car loans, home loans, etc.
• PAYMENT: This entity tracks payments related to loans. It includes attributes like PaymentID,
Amount, Date, and Time.
Assumptions:
• Each account has a unique AccountID.
• Each transaction and payment has a unique TransactionID and PaymentID, respectively.
• The AccountType attribute in the ACCOUNT entity differentiates between different types of accounts.
• The LoanType attribute in the LOAN entity differentiates between different types of loans.
Q.10 Consider the following relational database schema consisting of the four relation
schemas:
a. Get the details about all flights from Chennai to New Delhi.
πperson-name(Employee)
(2) Find city of employee whose name is ‘jashu’.
πcity(σ person-name=jashu(Employee))
(3) Find name and city of all employees who are having salary>50000.
The key fields are underlined, and the domain of each field is listed after the field name. Thus, sid is the key
for Suppliers, pid is the key for Parts, and sid and pid together form the key for Catalog. The Catalog relation
lists the prices charged for parts by Suppliers. Write the following queries in relational algebra.
2. Find the sids of suppliers who supply some red or green part.
3. Find the sids of suppliers who supply some red part or are at 221 Packer Ave.
4. Find the sids of suppliers who supply some red part and some green part.
8. Find the sids of suppliers who supply every red part or supply every green part.
9. Find pairs of sids such that the supplier with the first sid charges more for some part than the supplier with
the second sid.
10. Find the pids of parts that are supplied by at least two different suppliers.
11. Find the pids of the most expensive parts supplied by suppliers named Yosemite Sham.
12. Find the pids of parts supplied by every supplier at less than $200. (If any supplier either does not supply
the part or charges more than $200 for it, the part is not selected.
Solution: