Final Exam study Flashcards

(156 cards)

1
Q

WWhat are the 4 ways to communicate with a database management system?

A
  • DDL – data definition language
    E.g. Create, drop, alter, truncate, …
  • DQL – data query language
    E.g. Select
  • DML – data manipulation language
    E.g. Insert, update, delete
  • DCL – data control language
    E.g. Grant, revoke
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a paradigm in relation to database management systems?

A

In the context of database management systems (DBMS), a paradigm typically refers to a particular approach or model for structuring, storing, and manipulating data. The choice of paradigm will influence how data is represented, accessed, and modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the Key-Value Paradigm

A
  • EXAMPLES: REDIS, ORACLE NOSQL

A simple paradigm where every data item is stored as a key-value pair. This model is ideal for scenarios where quick access to data is crucial, and the relationship between data points is not significant. Redis and Riak are examples of key-value databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the Wide-Column Paradigm

A

This is is a database model designed for large-scale, distributed data storage. Instead of traditional fixed columns, it uses dynamic columns grouped into column families. Each row has a unique key and can have different columns. This model is optimized for querying vast amounts of distributed data. Popular databases using this paradigm include Apache Cassandra and Google Bigtable. They’re great for handling massive datasets and offer flexibility in data organization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the Document-Based Paradigm

A

This paradigm is prevalent in some NoSQL databases. Data is stored in documents, which can be in formats like JSON or XML. Each document can contain different fields, offering flexibility and scalability. MongoDB is a well-known example of a document-oriented database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Object Paradigm

A

This paradigm is built around the concept of objects, which combine both data and methods to operate on that data. Object-oriented databases aim to preserve the encapsulation, inheritance, and polymorphism principles of object-oriented programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the Graph-Based Paradigm

A

The Graph-Based paradigm is a database model that represents data as nodes (entities) and edges (relationships). It’s especially useful for understanding and analyzing complex relationships and interconnections. Popular databases like Neo4j use this paradigm. It’s ideal for scenarios where relationships between data points are central.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the Relational Paradigm

A

This is the most widely known and used paradigm. Based on relational algebra and set theory, it represents data in tables (or relations) with rows and columns. The SQL (Structured Query Language) is used to query and manipulate the data. Databases that adopt this paradigm are termed Relational Database Management Systems (RDBMS), and examples include MySQL, PostgreSQL, Microsoft SQL Server, and Oracle.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is inheritance

A

Entity Inheritance (Is-A relationship): This is where you have a general entity (sometimes called a parent or superclass) and a specialized entity (which can be thought of as a child or subclass). For example, consider an entity named “Vehicle” and another entity named “Car”. A “Car” is a type of “Vehicle”, so in this case, “Car” is a child of “Vehicle”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the different cardinalities in eer

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Hierachies

A

ER Hierarchies: In some diagrams, you might have a hierarchy of entities or relationships. The entities or relationships that derive or extend from a primary entity or relationship can be thought of as “children”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a disjoint constraint?

A

When sub-classes (or sub-types) of a specialization/generalization hierarchy are disjoint, it means that an instance (an individual object or entity) of the superclass (or parent entity) can belong to one, and only one, subclass. In other words, the subclasses don’t share any common instances. In many EER diagrams, this constraint is denoted by the letter “d” or by using a disjoint symbol.

For example, let’s say you have a superclass called “Vehicle” with two subclasses: “Car” and “Boat”. If the hierarchy is disjoint, then a specific vehicle can’t be both a car and a boat.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an overlap constraint?

A

When sub-classes (or sub-types) of a specialization/generalization hierarchy can overlap, it means that an instance of the superclass can belong to more than one subclass. This means there can be shared instances between subclasses. In many EER diagrams, this constraint is denoted by the letter “o” or by using an overlapping symbol.

Taking the above example, if the hierarchy is overlapping, then it’s possible for a specific vehicle to be classified both as a “Car” and a “Boat” (though this might not make logical sense in this particular example).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a Strong Entity?

A

In the context of Entity-Relationship (ER) and Enhanced Entity-Relationship (EER) diagrams, a strong entity is an entity that exists independently of any other entities in the diagram. In other words, it doesn’t rely on another entity to provide its primary key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an associative entity?

A

An associative entity in EER diagrams represents a many-to-many relationship between two entities, allowing for the capture of additional information about that relationship. It typically:

-Links Many-to-Many Relationships: For example, between “Students” and “Courses”.
-Holds Additional Attributes: Like “Date of Enrollment” in the relationship between students and courses.
-Uses a Composite Primary Key: Derived from the primary keys of the entities it connects, such as combining Student ID and Course ID.

In essence, it bridges two entities while capturing more data about their relationship.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a multi-valued attribute?

A

In an EER (Enhanced Entity-Relationship) diagram, a multi-valued attribute is an attribute that can have multiple values for a single entity instance.

Key Points:

-Representation: It’s usually represented by a double oval connected to the entity or relationship by a straight line.

-Example: Consider an entity “Person” and an attribute “Phone Numbers”. If a person can have multiple phone numbers, then “Phone Numbers” is a multi-valued attribute.

-Difference from Other Attributes: Standard attributes hold a single value (like a person’s first name). In contrast, multi-valued attributes can hold a set of values for each entity instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is Normalisation in relation to DBMS

A

Normalization in database management systems aims to organize data to minimize redundancy and improve data integrity. It involves:

Purpose:

-Reduce redundant data.
-Ensure logical data storage.
-Enhance data integrity.

Normal Forms: Levels of normalization include 1NF to 5NF, with most databases aiming for 3NF. Each form has specific criteria, like ensuring atomic values in 1NF and removing partial dependencies in 2NF.

Benefits:

-Reduces data anomalies.
-Minimizes redundancy.
-Streamlines data structure.

Trade-offs:

-Can increase table count, complicating queries.
-Might affect performance due to table joins.

Normalization is a balance between reducing redundancy and optimizing performance. Sometimes, databases are denormalized for performance needs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the CAP theorem?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is UNF to 3NF

A

In database management systems, the process of normalization involves organizing the attributes and relations of a relational database to minimize data redundancy and dependency. Normal forms (NF) are stages or levels of normalization. Here’s a quick overview from UNF (Unnormalized Form) to 3NF:

UNF (Unnormalized Form):

Raw data as it’s initially collected.
Contains duplicate data and lacks structural organization.
1NF (First Normal Form):

Each table has a primary key: uniquely identifying each record.
Attributes contain only atomic (indivisible) values, ensuring there are no repeating groups or arrays.
2NF (Second Normal Form):

All requirements of 1NF are met.
Every non-key attribute is fully functionally dependent on the primary key, which means there are no partial dependencies of any column on the primary key. This typically involves separating tables.
3NF (Third Normal Form):

All requirements of 2NF are met.
No transitive dependencies of non-key attributes on the primary key. In other words, non-key attributes must be functionally dependent only on the primary key.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is BCNF, 4NF, or 5NF
BCNF (Boyce-Codd Normal Form): A stricter version of 3NF. For any non-trivial functional dependency A→ Y, A must be a superkey. 4NF (Fourth Normal Form): Removes multi-valued dependencies. A table is in 4NF if it's in BCNF and has no multi-valued dependencies. 5NF (Fifth Normal Form or PJNF): Ensures data can be recomposed from sub-tables without loss or redundancy. A table is in 5NF if it's in 4NF and, for every non-trivial join dependency, the intersection of each pair is a superkey.
26
To display all the name of bus stop locations that is used as the starting point of a bus route.
27
None of the options are correct.
28
σQuantity > 5 (Product ⋈Product.ProductID = Order.ProductID Order)
29
The Student table may contain more than one student with the same age.
30
Trigger
31
Property JOIN Owner USING(OwnerID)
32
The correct answer is: None of these options are correct.
33
8
34
The correct answer is: A cursor handler is not compulsory
35
CALL Mystery7(5, @c);
36
ΠProductName, Price (Product)
37
Property JOIN Owner USING(OwnerID)
38
Can you give me an example of creating a table for students in SQL. There needs to be a student id (PK), first name, last name and age
CREATE TABLE Students ( StudentID INT PRIMARY KEY, FirstName VARCHAR(50), LastName VARCHAR(50), Age INT );
39
What is the syntax to insert values into a table in SQL?
INSERT INTO table_name (column1, column2, ... columnN) VALUES (value1, value2, ... valueN);
40
What is an example of the syntax to insert values into a table in SQL for Students?
INSERT INTO Students (StudentID, FirstName, LastName, Age) VALUES (1, 'John', 'Doe', 20);
41
What is the syntax to create a comment in SQL
It is "--"
42
What is the syntax to use a database in SQL
if the database is called "Database1" then the syntax is "use Database1"
43
If a value wants to be added with an int and the int needs to be a positive number what to you add to the line
UNSIGNED
44
If a value wants to be added with an int and the int needs to not be NULL what to you add to the line
NOT NULL
45
46
How to see information from a DBMS using SQL
Type the following: SELECT 'information' From databasename;
47
How to count the number of enrolmentIDS from denormalisation table
48
How to show all the information from the denormalisation table
49
Using the following information use SQL code to see how many enrolments does each student have
50
Using the following information use SQL code to see how many enrolments does each student have. Sort them by first name in descending order
51
Using the following information use SQL code to show me all the people who have 4 or more enrollments.
52
What is JOIN
-Returns rows when there is a match in both tables. -If there's no match, the row is not included in the result.
53
What is a left join
In SQL, a "LEFT JOIN" (or "LEFT OUTER JOIN") is a type of join that returns all records from the left table (the one that precedes the JOIN keyword), and the matched records from the right table (the one that follows the JOIN keyword). If there is no match, the result is NULL on the side of the right table.
54
what is the syntax for left join
SELECT columns FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
55
Please create a left join of the following tables
SELECT Table1.name, Table2.age FROM Table1 LEFT JOIN Table2 ON Table1.id = Table2.id;
56
What is a right join
In SQL, a "RIGHT JOIN" (or "RIGHT OUTER JOIN") is a type of join that returns all records from the right table (the one that follows the JOIN keyword), and the matched records from the left table (the one that precedes the JOIN keyword). If there is no match, the result is NULL on the side of the left table. The basic syntax for a RIGHT JOIN is similar to that of a LEFT JOIN, but the tables are switched in terms of their position related to the JOIN keyword:
57
What is the syntax for a right join
SELECT columns FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
58
What is a union in sql
In SQL, the UNION operator is used to combine the result sets of two or more SELECT statements. It removes duplicate rows between the various SELECT statements. Each SELECT statement within the UNION must have the same number of columns in the result sets with similar data types. The columns in each SELECT statement must also be in the same order.
59
What is the syntax for a union
SELECT column_name(s) FROM table1 UNION SELECT column_name(s) FROM table2; For example, if you have two tables, table1 and table2, that both contain a column for name, you could combine the names from both tables while removing duplicates with the following query: SELECT name FROM table1 UNION SELECT name FROM table2; If you want to include all duplicates, you would use UNION ALL: SELECT name FROM table1 UNION ALL SELECT name FROM table2;
60
What is the selection operator?
61
What is the projection Operator?
62
What is the Cartesian Product Operator
63
What is the Union Operator
64
What is the Set Difference Operator
65
What is the Intersection Operator
66
What is the Theta-join Operator
67
What is the Natural Join Operator
68
What is the Semijoin Operator
69
What is the Antijoin Operator
70
What is the Outer Join Operator
71
Please provide the normal sql implementation and the procedural SQL implementation
72
What is a database stored program?
A database stored program is a computer program that is stored and executed within the database server.. It contains a series of instructions written in mySQL procedural language. Each stored procedure is associated with a name. The source code and (sometimes) any compiled version of the stored program are always held within the database servers system tables. When the program is executed, it is executed within the memory address of a database server, process or thread. This is also called a stored module or a stored routine.
73
What are the three types of MySQL Stored Programs and explain them
74
What does MySQL’s Procedural Extension of SQL support?
75
What is the syntax to declare a variable
76
When do you use the DELIMITER // command?
In MySQL, the DELIMITER command is used to change the standard delimiter, which is the semicolon (;), to another sequence of characters. This is particularly useful when you want to define stored procedures, functions, triggers, or other database objects that contain multiple SQL statements. An example of this is as follows: DELIMITER // CREATE PROCEDURE myProcedure() BEGIN -- Procedure definition goes here, semicolons can be used without ending the procedure SELECT 'Hello, World!'; END// DELIMITER ;
77
What is the syntax to create a stored procedure
78
How do you execute a stored procedure
79
80
What is the syntax on how to create a stored procedure, how to end one and what a procedure of hello world would look like
81
What is the select ... INTO statement
The SELECT INTO statement in SQL is used to select data from one table and insert it into a new table. This can be very useful when you need to create a backup copy of a table or to extract a subset of data for further processing.
82
What is a cursor?
83
create a procedure to give rise to credit limit to all the customers
84
What is Error Handling in Stored Procedures
85
What is the syntax of ERror handlers
86
What are Database Triggers
87
What is the general syntax for triggers?
88
89
What is The Notion of a Transaction
90
What is the Transaction State Transition Diagram
91
What are the Outcomes of a Transaction
92
What are the Four basic (ACID) properties that define a transaction:
93
What is the Source of Database Inconsistency
94
What is the Lost Update Problem?
95
What is the Uncommitted Dependency/Dirty Read Problem
96
What is the Inconsistent Analysis Problem/Unrepeatable Read Problem
97
What are the Conflicts among Concurrent Transactions
98
How to prevent concurrency anomalies?
99
What is a Schedule
100
What is a Serial Schedule
101
What is a Nonserial Schedule
102
Serial or Nonserial Schedule?
103
What is Serializability
104
In serializability why is ordering of reads/writes important:
105
What is Serializable Schedule
106
What is Conflict Serializability
107
How do you Test for Conflict Serializability
108
What are the Two basic concurrency control techniques:
- Locking - Timestamping Both are conservative approaches: delay transactions in case they conflict with other transactions.
109
What are Lock-Based Protocols
110
What are the Locking Basic Rules
111
What is Two-Phase Locking (2PL)
112
What is Deadlock
113
What is Starvation
114
What is Timeout
115
What is Deadlock Prevention
116
What is the "Deadlock Prevention: Wait-Die Scheme"
117
What is the "Deadlock Prevention: Wound-Wait Scheme"
118
What is Deadlock Detection
119
What is Deadlock Recovery
120
What is Timestamping
121
What is Timestamping: Read/Write
122
What is Optimistic Techniques
123
What are the Types of Database Failures
124
How to you Deal with Database Failures
125
What are the Transaction and Recovery methods for a database failure
126
What is the Data Access Model
127
What facilities should the DBMS provide to assist with recovery?
128
What is a Log File
129
What is Log-Based Recovery
130
What is the three main recovery techniques for
131
What is Recovery Techniques: Deferred Update
132
What is Recovery Techniques: Immediate Update
133
What is Immediate Update
134
What is Checkpointing
135
What is Shadow Paging
136
What is a transitive dependencies in sql?
A transitive dependency in a database occurs when one non-prime attribute is dependent on another non-prime attribute via a transitive relation. In simpler terms, this means that attribute A depends on attribute B, which then depends on attribute C, where C is a candidate key (a column or set of columns that can uniquely identify any database record without referring to any other data), and A and B are not candidate keys. Here's an example to illustrate transitive dependency: Consider a table with three columns: StudentID, Class, and TeacherName. - StudentID is a primary key, so each record is unique to a student. - Class is determined by the StudentID (a student takes a specific class). - TeacherName is determined by the Class (a specific teacher teaches a specific class). In this case, TeacherName has a transitive dependency on StudentID through Class. TeacherName does not depend directly on StudentID; it depends on which Class the student is taking. According to 3NF, this transitive dependency should be removed to prevent anomalies and redundancy in the database. This is typically done by splitting the table into two: A Students table with StudentID and Class. A Classes table with Class and TeacherName. Now, TeacherName is directly dependent on Class, which is a candidate key in the Classes table, and the transitive dependency is resolved. This normalization process helps ensure that each table contains data related only to a single concept or entity, reducing redundancy and improving data integrity.
137
What are the cardinalities with the numbers then?
1..1 (One-to-One): An entity on one side of the relationship is associated with exactly one entity on the other side. For example, each person has exactly one passport, and each passport is assigned to exactly one person. 0..1 (Zero or One-to-One): An entity on one side of the relationship is associated with zero or one entity on the other side. For example, a person might have zero or one driver's license. *1.. (One-to-Many)**: An entity on one side (the "one" side) is associated with zero, one, or multiple entities on the other side (the "many" side). For example, a mother (one) has children (many). *0.. (Zero-to-Many)**: An entity on one side does not need to be associated with an entity on the other side, but it can be. For example, a teacher (one) could have zero, one, or many students (many). .. (Many-to-Many): Entities on both sides of the relationship can have zero, one, or many associations to the other side. For example, students (many) can enroll in multiple courses (many), and each course can have multiple students.
138
Describe the concept of entity integrity.
Entity integrity is a concept within the realm of relational databases that ensures each row (or record) in a table is uniquely identifiable. This is a critical aspect of database design and integrity constraints, and it is achieved through the proper use of primary keys.
139
What is a functional dependency
A functional dependency in a relation occurs when one attribute uniquely determines another attribute. This relationship is denoted as A → B, which means "B is functionally dependent on A." If you know the value of A, you can determine the corresponding value of B.
140
What are the differences between 2NF and 3NF
Suppose you have a table like this: Sales Order Table: OrderID (Primary Key) ProductID (Part of Composite Key) OrderDate CustomerID CustomerName ProductName To convert this table into 2NF, we must remove partial dependencies. If ProductID and OrderID together form a composite key, and ProductName is dependent only on ProductID, then ProductName should be moved to a separate table where ProductID is the primary key. After moving to 2NF: Sales Order Table (2NF): OrderID (Primary Key) ProductID OrderDate CustomerID Product Table (2NF): ProductID (Primary Key) ProductName To convert the "Sales Order Table" into 3NF, we must remove transitive dependencies. If CustomerName is dependent on CustomerID (and CustomerID is not a candidate for a primary key of the "Sales Order Table"), then CustomerName should be moved to its own table. After moving to 3NF: Sales Order Table (3NF): OrderID (Primary Key) ProductID OrderDate CustomerID Customer Table (3NF): CustomerID (Primary Key) CustomerName
141
Write a SQL query to display the coffee supplier (name and contact number) located in NSW who supplies the most number of coffee brands.
SELECT S.s_name, S.s_contact, COUNT(DISTINCT BS.b_id) AS brand_count FROM Supplier AS S JOIN BrandSupplier AS BS ON S.s_id = BS.s_id WHERE S.s_state = 'NSW' GROUP BY S.s_id ORDER BY brand_count DESC LIMIT 1;
142
Given the statement as follow: SELECT * FROM Coffee c LEFT JOIN Brand b ON c.b id = b.b id JOIN BrandSupplier bs ON b.b id = bs.b id; Is it possible to rewrite the query above using RIGHT JOIN without compromising the results? If it is possible, provide the rewritten version of the RIGHT JOIN query that would result in the same data. If not, provide the reason why.
Yes it is SELECT * FROM BrandSupplier bs JOIN Brand b ON bs.b_id = b.b_id RIGHT JOIN Coffee c ON b.b_id = c.b_id;
143
Which is more optimal between the usage of subquery versus join? Is one always more efficient than the other? Illustrate your argument by using the schema
Performance should be evaluated on a case-by-case basis, often using the EXPLAIN statement or equivalent in your SQL database to analyze the query execution plan. It's also good practice to consider the readability and maintainability of the SQL queries. For critical performance cases, you should benchmark both methods under realistic data loads and query conditions.
144
A query was created by an intern as follow: SELECT s name, s contact FROM Supplier, BrandSupplier WHERE s state = ' A' OR s country = 'USA' AND priority < 3 ORDER BY s name; Explain what could possibly be the intended purpose of this query. Do you think this query is a well-written query? Explain.
The intended purpose of the query appears to be to retrieve the names and contact information of suppliers from the Supplier table who are either located in the state 'A' or the country 'USA' and have a priority less than 3 in the BrandSupplier table. The ORDER BY s_name clause suggests that the results should be ordered alphabetically by the supplier's name. The query is not well written because the query uses an old style join syntax, its missing its join condition and has ambiguous boolean logic.
145
What is the purpose of the stored procedure provided above? suggest an alternate name to Mystery. What is the purpose of the parameter called ‘something’, what could be a good name for the parameter instead of ‘something’ ?
The provided stored procedure, named Mystery, seems to have two primary actions: It counts the number of suppliers in the Supplier table and assigns this value to an OUT parameter named something. It then selects the names of all suppliers from the Supplier table and returns this as a result set. The purpose of the something OUT parameter is to hold the count of supplier records in the Supplier table after the procedure is executed. The procedure itself does not do anything with this count within its own body; it simply provides the count to the caller. A more descriptive name for the stored procedure might be GetSupplierCountAndNames, which reflects the actions being taken within the procedure.
146
Can triggers be used to enforce some business rules? If yes, provide a brief example in your own words describing how. If no, describe why this is not the case and what alternatives might be used to enforce business rules
Yes, triggers can be used to enforce business rules in a database system. A trigger is a database object that is automatically executed or fired when certain events occur. Triggers are often used to enforce complex business rules that cannot be enforced using the standard constraints provided by the database management system (DBMS), such as CHECK, UNIQUE, PRIMARY KEY, or FOREIGN KEY constraints Suppose you have a business rule that states "a customer's account balance must never go below zero." This is a rule that you might enforce using a trigger.
147
complete the following template of a procedure to insert a new record into the Brand table. The new record should be assigned with the next value of the existing brand IDs. If the latest record of a brand has the ID of 5, then the new one should be assigned with ID 6. CREATE PROCEDURE insertBrand (IN brandName TEXT) BEGIN -- your code here END
DELIMITER // CREATE PROCEDURE insertBrand (IN brandName TEXT) BEGIN -- Declare a variable to hold the new ID DECLARE newId INT; -- Find the maximum brand ID currently in use and add 1 to it to get the new ID SELECT MAX(b_id) + 1 INTO newId FROM Brand; -- Check if the newId is NULL which means the Brand table is empty, then start from 1 IF newId IS NULL THEN SET newId = 1; END IF; -- Insert the new brand with the calculated new ID INSERT INTO Brand (b_id, b_name) VALUES (newId, brandName); END // DELIMITER ;
148
What is Lost Update
This occurs when two transactions that access the same data are interleaved in such a way that the modifications made by one transaction are overwritten by another. The update made by the first transaction is lost by the time the second transaction is committed.
149
What is Unrepeatable Read
This happens when a transaction reads the same row twice and gets a different value each time. This is usually because another transaction has updated or deleted that row after the first read.
150
What is Dirty Read
A dirty read occurs when a transaction reads data written by a second transaction that has not yet committed. If the second transaction rolls back, the first transaction will have read data that was never officially in the database.
151
briefly describe the concepts of lost update, unrepeatable read, dirty read. Are any of these present in the schedule above? If so, which ones?
Considering the sequence of operations: Lost Update: This could potentially be an issue with the writes to X by T2 and T4. If T2's first write is considered an update based on a value of X that T1 read, and then T4 writes over it before T2's second write, T2's first update to X could be lost. However, it's not clear from the schedule if T2's first write is indeed an update based on T1's read or an independent write. If it is independent, then there's no lost update. If it's based on T1's read, then the lost update could be present because of T4's subsequent write. Unrepeatable Read: There is no indication that any transaction reads the same value twice, so we cannot confirm the presence of an unrepeatable read in the given schedule. Dirty Read: No transaction is reading data that has been written by a transaction that has not yet committed. T4 writes to X and then commits, and there are no reads of X by other transactions between T4's write and commit. Therefore, there are no dirty reads in the given schedule.
152
Is the schedule S conflict serialisable? If yes, why? If no, why not?
153
What is the concept of the write-ahead log protocol, and why is it useful in database recovery mechanisms? Try to limit your answer to under 100 words.
The write-ahead logging (WAL) protocol is a method used in databases to ensure that changes to data are not written to the main storage before the corresponding log record is written to persistent storage. This protocol ensures that the log precedes the actual data changes, enabling the database to recover to a consistent state after a crash by redoing committed transactions and undoing uncommitted transactions using the log. It is crucial for maintaining database integrity and consistency in the event of system failures.
154
With an immediate database modification strategy in place, which transactions should be redone and which transactions should be undone?
155
Assuming W, X, Y all started at 300 before these T0 started, what would the final values of W, X and Y be after the recovery has been performed? Explain what happens in the recovery process to get to those values (you can refer to your previous answers in this question).
156