VTU DBMS Module 4 & 5 Key Questions
VTU DBMS Module 4 & 5 Key Questions
Assertions are used to enforce constraints that apply to the entire database, ensuring data integrity. For example, the assertion 'CREATE ASSERTION SALARY_CONSTRAINT CHECK ( NOT EXISTS (SELECT * FROM EMPLOYEE E, EMPLOYEE M, DEPARTMENT D WHERE E.Salary > M.Salary AND E.Dno = D.Dnumber AND D.Mgr_ssn = M.Ssn ) );' checks that no employees earn more than their managers. Triggers are procedural code that automatically execute in response to certain events on a table, such as INSERT, UPDATE, or DELETE. An example of a trigger is 'CREATE TRIGGER EmpBonus BEFORE INSERT OR UPDATE ON Employee FOR EACH ROW BEGIN :NEW.bonus := :NEW.salary * 0.03; END;', which calculates and sets a 3% bonus on the new salary being inserted or updated in the employee table .
The Two Phase Locking (2PL) Protocol is a concurrency control method that ensures serializability in transactions by dividing lock operations into two phases: the Growing Phase, where transactions can acquire all the necessary locks but not release any, and the Shrinking Phase, where transactions can release locks but not acquire any new ones. There are different types of 2PL: Basic 2PL, Strict 2PL, which holds exclusive locks until a transaction is committed or aborted, and Rigorous 2PL, which holds all locks until the end of the transaction, thereby preventing any other transaction from accessing data being used by the current transaction .
Document-based NoSQL systems, like MongoDB, store data in JSON-like documents offering a flexible, schema-less design. This allows for hierarchical storage structures, efficiently managing complex data. Basic CRUD operations in MongoDB include: Create, which can be executed using 'db.students.insertOne({name: "Alice", age: 21})'; Read, using 'db.students.find({name: "Alice"})' to retrieve data; Update, utilizing 'db.students.updateOne({name: "Alice"}, {$set: {age: 22}})' to modify existing data; and Delete, with 'db.students.deleteOne({name: "Alice"})' to remove documents from collections .
Graph databases, such as Neo4j, store data as nodes and relationships (edges), making them particularly suitable for handling complex, interconnected data. They excel in applications involving social networks, recommendation engines, and networked operations where relationships are critical. Neo4j utilizes the Cypher query language for data manipulation. For example, a query like 'CREATE (a:Person {name:'Alice'})-[:KNOWS]->(b:Person {name:'Bob'})' models a relationship, which can be queried back with 'MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name, b.name'. Such features enable efficient traversal and querying of data relations .
The Two Phase Locking Protocol ensures transaction serializability by maintaining a clear separation between the growing and shrinking phases of a transaction. In the Growing Phase, a transaction can acquire all the necessary locks but is prohibited from releasing any, ensuring that once a lock is acquired, it preserves the current state from modification by other transactions. In the Shrinking Phase, the transaction can release locks but cannot acquire any new ones, preventing any subsequent transaction from accessing or affecting the resources until the locks are released. This strict management of lock operations guarantees that transactions are executed in a manner akin to serial execution, preserving data consistency and preventing anomalies like lost updates or uncommitted data reads .
NoSQL databases are non-relational databases designed to maintain scalability and flexibility, often lacking a fixed schema. Examples include MongoDB, Cassandra, and Neo4j. The CAP Theorem states that it is impossible for a distributed data store to simultaneously provide all three of the following guarantees: Consistency, ensuring the same data across nodes; Availability, ensuring that every request receives a response; and Partition Tolerance, allowing the system to continue functioning despite network failures. Distributed system designs must choose which two of these they prioritize .
Triggers enhance data integrity and automation by automatically enforcing rules and executing procedures in response to specified events such as INSERT, UPDATE, or DELETE operations. By doing so, they ensure that business rules and data constraints are consistently applied without manual intervention. For instance, a trigger might automatically calculate and update a bonus whenever an employee's salary record is modified, ensuring financial records remain accurate and consistent. This not only reduces human error but also streamlines processes by eliminating the need for manual checks or adjustments, ultimately improving the reliability and consistency of database operations .
In a database management system, transactions go through several states: Active, Partially Committed, Committed, Failed, and Aborted. 1. Active: The initial state where the transaction is in progress. 2. Partially Committed: When the final statement of the transaction has been executed but not yet saved. 3. Committed: After successful execution, indicating that changes have been made permanent. 4. Failed: If an error occurs during execution, the transaction enters this state. 5. Aborted: After a transaction is rolled back due to failure. Additional operations include: BEGIN, which marks the start of a transaction; COMMIT, which saves the changes made during the transaction; ROLLBACK, which undoes changes; and SAVEPOINT, which sets a point to which a transaction can roll back instead of rolling all the way back .
Rollback operations in transaction management are critical for maintaining database integrity and reliability. They allow a database to revert to a known consistent state in the event of transaction failure, preventing partial transactions from corrupting the database. By providing a mechanism to undo changes made by the transaction that failed, rollback operations protect data integrity and ensure that only successfully completed transactions (those that reach the commit state) affect the database. This capability is essential to support the ACID properties—specifically, atomicity—ensuring transactions are all-or-nothing processes .
NoSQL databases are preferred over traditional relational databases when dealing with large volumes of diverse data types that require high scalability, flexibility, and fast performance without a predefined schema. Applications such as social networking sites, real-time analytics, content management systems, and other domains experiencing rapid iterative development benefit from NoSQL's ability to efficiently manage extensive, semi-structured data and horizontal scaling. Additionally, use cases requiring quick adaptability to changing data models, such as Big Data applications, are suited for NoSQL due to its schema-less nature and support for distributed computing .