Professional Documents
Culture Documents
Dbms Assignment 2
Dbms Assignment 2
The ER model visually represents entities (real-world objects) and their relationships
in a database. A many-to-many relationship occurs when a single entity instance can
be associated with multiple instances of another entity, and vice versa.
Associative Entities:
Imagine tables for Students and Courses. A student can enroll in multiple courses,
and a course can have many students. An associative entity named "Enrollment" can
be created with attributes like "enrollment_id" (primary key), "student_id" (foreign key
referencing Students), "course_id" (foreign key referencing Courses), and potentially
"semester" or "grade."
Entities:
o Student (attributes: student_id, name, major, etc.)
o Course (attributes: course_id, name, department, credits, etc.)
o Department (attributes: department_id, name, college, etc.)
o Professor (attributes: professor_id, name, department, etc.) (Optional)
Relationships:
o A Student ENROLLS_IN many Courses (Many-to-Many, with
Enrollment as the associative entity)
o A Course belongs to a DEPARTMENT (One-to-Many)
o A Professor TEACHES many Courses (Many-to-Many, optional
depending on the data model)
Cardinalities:
A Student can enroll in many Courses (1:N)
A Course can have many Students enrolled (N:1)
A Department can have many Courses (1:N)
A Course belongs to one Department (N:1)
A Professor can teach many Courses (1:N) (Optional)
A Course can be taught by many Professors (N:1) (Optional)
Example: Student Enrollment
The choice between ER and hierarchical models depends on the data structure. ER
models are more flexible for complex relationships, while hierarchical models excel
at representing strict hierarchies. The university database with its many-to-many
relationships would be better suited for an ER model.
What does the DIVISION operator in relational algebra
represent?
OR
Describe the role of the WHERE clause in SQL
queries. Provide an example query with a
WHERE clause and discuss how it filters roÄvs based
on specified conditions
(a) Short Answer: DIVISION Operator in Relational Algebra
Imagine a library database with tables for Books and Borrowings. A single column
like "book_id" might not be unique if there are multiple editions of the same book.
Here, a composite key using "book_id" and "edition_number" would ensure unique
identification of each book instance.
(c) Why is achieving Second Normal Form (2NF) important, and how
does it difTer from First Normal Form (INF)?
OR
A partial dependency occurs when a non-key attribute (attribute not part of the
primary key) depends on only a part of the primary key, not the entire key. This can
lead to data redundancy and inconsistency issues.
Contribution to Normalization
Example:
Consider a table named "Sales" with columns: "Order ID", "Customer Name",
"Product ID", "Product Name", "Quantity", and "Price". This table might have partial
dependencies: "Customer Name" depends on "Order ID", and "Product Name" and
"Price" depend on "Product ID".
By decomposing this table:
Q.4 (a) Which term is used to describe a situation where two or more transactions
are waiting indefinitely for each other to release locks, leading to a system
standstill?
What are the techniques for concurrency control?
(b)
(a) Deadlock
This term describes a situation where two or more transactions are waiting
indefinitely for each other to release locks on resources (data items) they need to
complete their operations. This creates a standstill as no transaction can proceed,
leading to a system halt.
applied to the database. This eliminates the risk of inconsistent data states where
Both debits (from A) and credits (to B) are completed successfully, updating both
accounts.
If any step fails (e.g., insufficient funds), the entire transaction is rolled back, leaving
neither account modified.
(d) Two-Phase Commit (2PC) in Distributed Transactions
2PC Phases:
1. Prepare Phase: The coordinator node (a designated server) sends a "prepare"
message to all participating nodes. Each node performs the required operations
locally and logs the updates, but doesn't permanently commit them to the database.
2. Commit or Rollback: Based on the responses from all nodes (success or failure),
the coordinator decides:
o Commit: If all nodes confirm readiness, the coordinator sends a "commit"
message to all nodes, instructing them to permanently apply the updates.
o Rollback: If any node encounters an error or reports failure, the coordinator
sends a "rollback" message, instructing all nodes to undo the local changes
performed during the prepare phase.
Example Scenario:
B-Trees are a widely used data structure for creating multi-level indexes. They offer
efficient searching and insertion/deletion operations:
Hash functions don't directly contribute to data integrity in databases. However, they
can be used in conjunction with other techniques to enhance data verification.
Hashing for Verification: Hash functions are one-way mathematical
functions that map data to a fixed-size value (hash). This hash can be stored
along with the original data. When the data is modified, the hash value will
also change. By recalculating the hash and comparing it to the stored value,
you can detect data inconsistencies or tampering.
Important Note: Hash functions alone don't guarantee data integrity because
collisions (different data producing the same hash) can occur. They are typically
used along with other mechanisms like digital signatures or cryptographic
checksums for complete data integrity.
(d) Clustered and Covering Indexes for Range Queries
Clustered Indexes:
Reorder the physical storage of table data based on the indexed column(s).
Optimize performance for range queries that involve the indexed column(s) as
the starting or ending points.
Since data is physically clustered based on the index, the database can
efficiently access contiguous data blocks during a range query, reducing disk
I/O operations.
Covering Indexes:
Include additional columns in the index besides the column(s) used for
searching.
Allow the database engine to potentially satisfy the entire query (including
filtering or joining) using only the index itself, without needing to access the
actual table data.
This optimizes performance for queries that involve filtering or joining based
on the columns included in the covering index.
Example Scenario:
A clustered index on "price" would improve performance for queries like "find
products priced between $100 and $200". The physical clustering based on
price allows the database to scan through contiguous data blocks efficiently.
A covering index on "category" and "price" would allow filtering products by
category (e.g., "electronics") and price range (e.g., "$100-$200") to be
potentially answered using the index itself, without needing to access the
entire table data.
Alternative: Significance of Primary Indexes
Primary Index Importance: