QB Solved m3
QB Solved m3
QB Solved m3
For the relation schema below, give an expression in SQL for each of the queries that
follows:
employee (ID, person_name, street, city)
works (ID, company_name, salary)
company ( company_name, city)
manages (ID, manager_id)
i) Find the employees whose name starts with ‘C’.
ii) Find the name of managers of each company.
iii) Find the ID, name, and city of residence of employees who works for “First
Bank Corporation” and earn more than Rs50000.
iv) Find the name of companies whose employees earn a higher salary, on
average, then the average salary at “First Bank Corporation”.
Consider the following relations for a database that keeps track of business trips of
salespersons in a sales office:SALESPERSON(Ssn, Name, StartYear, DeptNo)
a) A trip can be charged to one or more accounts. Specify the foreign keys for this
schema, stating any assumptions you make.
b) Write relational algebra expressions to get the details of salespersons who have
traveled between Mumbai and Delhi and the travel expense is greater than Rs. 50000.
c) Write relational algebra expressions to get the details of the salesperson who had
incurred the greatest travel expenses among all travels made.
For the TRIP relation, the foreign key is Ssn, which references the Ssn attribute in the
SALESPERSON relation. This indicates that each trip is associated with a salesperson.
For the EXPENSE relation, the foreign key is TripId, which references the TripId
attribute in the TRIP relation. This indicates that each expense is associated with a trip.
b) Relational algebra expressions to get the details of salespersons who have traveled
between Mumbai and Delhi and the travel expense is greater than Rs. 50000:
b) Find the names of suppliers supplying some green parts for less than Rs 1000:
π_sname((σ_color='green' ∧ cost < 1000 (Catalog)) ⨝ Suppliers)
c) Find the IDs of suppliers who supply some red or green parts:
π_sid((σ_color='red' ∨ color='green' (Parts)) ⨝ Catalog)
Consider the query SELECT NAME, AGE FROM STUDENT WHERE GENDER
=‘Male’ on the table STUDENT (ROLLNO, NAME, AGE, GENDER, ADDRESS). Give
a relational algebra expression corresponding to the query. Is the result produced by the
query and your expression always the same? Why?
π_NAME, AGE(σ_GENDER='Male'(STUDENT))
Static Hashing:
● In static hashing, the size of the hash table is fixed and does not change over
time.
● The hash function determines the bucket (or slot) to which each record is
mapped based on a predetermined number of buckets.
● If the number of records increases beyond the capacity of the hash table, it can
lead to an increase in collisions, which can degrade performance.
● Rehashing is required if the number of records exceeds the initial capacity of
the hash table. Rehashing involves creating a new, larger hash table,
recalculating the hash values for all records, and redistributing the records into
the new hash table.
● Static hashing is simple to implement and suitable for scenarios where the size
of the dataset is relatively stable and known in advance.
Dynamic Hashing:
● In dynamic hashing, the size of the hash table can change dynamically based
on the number of records in the dataset.
● Dynamic hashing typically uses techniques like extendible hashing or linear
hashing.
● Extendible hashing uses a directory structure to dynamically adjust the number
of buckets based on the number of records.
● Linear hashing dynamically adjusts the number of buckets by splitting or
merging buckets as needed.
● Dynamic hashing adapts more flexibly to changes in the dataset size and can
reduce the likelihood of collisions, leading to better performance in dynamic
environments with unpredictable data growth.
● However, dynamic hashing can be more complex to implement compared to
static hashing due to the need for dynamic adjustments to the hash table
structure.