You are on page 1of 18

Question 1:

(a) Explain the following terms:

1. BCNF (Boyce-Codd Normal Form):

BCNF is a database normalization technique used to eliminate certain types of data anomalies in
relational databases. When a database table is in BCNF, it means that every determinant (a column
or a set of columns that uniquely determines another column's value) in the table is a candidate key.
In simpler terms, BCNF ensures that there are no partial dependencies, where a non-key attribute
depends on only a part of the primary key, and no transitive dependencies, where a non-key
attribute depends on another non-key attribute.

2. Concurrency Control:

Concurrency control is a mechanism used in database management systems to ensure that multiple
transactions can access and modify shared data concurrently without causing data inconsistencies or
conflicts. The primary goal of concurrency control is to maintain data integrity and consistency while
allowing concurrent access to the database. Various techniques, such as locking, timestamp ordering,
and optimistic concurrency control, are employed to manage the execution of transactions and avoid
issues like data corruption, lost updates, or conflicts.

(b) Differentiate between primary key and foreign key:

Primary Key:

- A primary key is a unique identifier for each record (row) in a database table.

- It ensures that each row in the table can be uniquely identified.

- There can be only one primary key in a table.

- It enforces entity integrity, meaning it ensures that each record is distinct and identifiable.

Foreign Key:

- A foreign key is a column or a set of columns in a table that refers to the primary key of another
table.

- It establishes a relationship between two tables by referencing the primary key of the related table.

- It ensures referential integrity, meaning it ensures that values in the foreign key column(s) match
the values in the primary key column of the referenced table.

- There can be multiple foreign keys in a table, each pointing to a different related table.
(c) Constraints in SOL (Structured Query Language):

In the context of the Structured Query Language (SQL), constraints are rules or conditions applied to
the columns of a database table to enforce data integrity and maintain consistency. Constraints help
to ensure that the data stored in the database follows specific rules, and they prevent the insertion
of invalid or inconsistent data. Some common types of constraints in SQL are:

1. Primary Key Constraint: Ensures that a column or a set of columns uniquely identify each row in
the table. It prevents duplicate and NULL values in the specified column(s).

Example:

```sql

CREATE TABLE Employees (

emp_id INT PRIMARY KEY,

emp_name VARCHAR(50),

emp_dept VARCHAR(50)

);

```

2. Foreign Key Constraint: Establishes a link between two tables, where the values in the specified
column(s) of one table must match the values of the primary key column(s) in another table.

Example:

```sql

CREATE TABLE Orders (

order_id INT PRIMARY KEY,

product_id INT,

customer_id INT,

FOREIGN KEY (product_id) REFERENCES Products(product_id),

FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)

);

```
3. Unique Constraint: Ensures that all values in the specified column(s) are unique, but unlike the
primary key constraint, it allows NULL values.

Example:

```sql

CREATE TABLE Students (

student_id INT UNIQUE,

student_name VARCHAR(50),

batch_id INT

);

```

(d) Differentiate between weak entity and strong entity with an example:

Strong Entity:

- A strong entity is an entity in a database that exists independently and has its attributes.

- It is not dependent on any other entity for its existence.

- It is represented by a regular rectangle in an Entity-Relationship Diagram (ERD).

Example: Consider an "Author" entity in a book database. Each author has a unique identifier
(author_id), and they can have attributes like name, nationality, and birthdate. The "Author" entity
can exist on its own and does not rely on any other entity to be meaningful.

Weak Entity:

- A weak entity is an entity in a database that depends on another entity (strong entity) for its
existence.

- It has its attributes but also has a partial or total dependency on the strong entity.

- It is represented by a rectangle with double lines in an Entity-Relationship Diagram (ERD).

Example: In the same book database, consider a "Book" entity. A book can have a unique identifier
(book_id) and attributes like title, genre, and publication year. However, a "Book" entity might also
require an association with a specific "Publisher" entity. Without a publisher, a book cannot be
uniquely identified or exist in the database. In this case, the "Book" entity would be considered a
weak entity, and "Publisher" would be the strong entity it depends on.

Question 2
(a) DBMS (Database Management System):

A Database Management System (DBMS) is software that allows users to interact with databases and
efficiently manage large volumes of data. It serves as an intermediary between the user and the
database, providing a well-organized and secure way to store, retrieve, update, and manage data.
Some features of DBMS include:

1. Data Definition Language (DDL): DBMS provides DDL statements to define and manage the
structure of the database, including creating, modifying, and deleting database objects like tables,
indexes, and views.

2. Data Manipulation Language (DML): DBMS offers DML statements to interact with the data stored
in the database, allowing users to insert, update, delete, and retrieve records.

3. Data Integrity: DBMS enforces data integrity by applying constraints like primary keys, foreign keys,
unique keys, and check constraints to maintain accurate and consistent data.

4. Data Security: DBMS implements security measures like user authentication, authorization, and
access control to ensure that only authorized users can access and modify the data.

5. Concurrent Access and Transaction Management: DBMS supports concurrent access to the
database by multiple users while ensuring data consistency through transaction management, which
allows multiple operations to be grouped as a single unit of work.

6. Data Backup and Recovery: DBMS facilitates data backup and recovery mechanisms to protect
data from loss due to hardware failures, crashes, or other disasters.

(b) Group by and Order by clause:


Group by Clause:

The GROUP BY clause is used in SQL to group rows with similar values into summary rows based on
one or more columns. It is often used in combination with aggregate functions (e.g., SUM, COUNT,
AVG) to generate summary reports. The result set is reduced to unique combinations of values in the
specified columns, and aggregate functions are applied to each group.

Example:

Consider a table "Sales" with columns "Product," "Category," and "Revenue." To calculate the total
revenue for each product category, you can use the GROUP BY clause as follows:

```sql

SELECT Category, SUM(Revenue) AS TotalRevenue

FROM Sales

GROUP BY Category;

```

Order by Clause:

The ORDER BY clause is used to sort the result set in ascending (default) or descending order based
on one or more columns. It is helpful when you want to present the data in a specific order for
readability or analysis.

Example:

Using the previous "Sales" table, if you want to see the product categories with the highest total
revenue first, you can combine GROUP BY with ORDER BY like this:

```sql

SELECT Category, SUM(Revenue) AS TotalRevenue

FROM Sales

GROUP BY Category

ORDER BY TotalRevenue DESC;

```

(c) Disadvantages of file processing system:


1. Data Redundancy: In a file processing system, data is often duplicated and stored in multiple files.
This redundancy wastes storage space and can lead to data inconsistencies and anomalies when
updates are made to one file and not propagated to others.

2. Data Inconsistency: Since data is spread across multiple files and applications, maintaining data
consistency becomes challenging. Changes made in one file may not reflect in others, leading to
discrepancies.

3. Lack of Data Integrity: File systems usually lack built-in mechanisms to enforce data integrity rules
like primary key constraints or referential integrity, making it easier for invalid data to enter the
system.

4. Limited Data Sharing: In a file processing system, data access is restricted to specific applications,
making it difficult to share data across different departments or users, leading to data silos.

5. Difficulty in Data Retrieval: Retrieving specific data requires navigating through various files, which
can be time-consuming and complex, especially as the data volume grows.

6. Data Security Concerns: File processing systems often lack robust security features, making it
harder to control access to sensitive data and protect it from unauthorized access.

(d) Serializable Scheduling:

In the context of databases, a serializable schedule is a type of transaction schedule that produces
the same result as if the transactions were executed serially, one after the other, without any
overlap. It ensures that the final state of the database after concurrent execution is equivalent to the
state that would have been obtained if the transactions had executed sequentially in some order.

Example:

Let's consider two transactions, T1 and T2, and a database with a single account balance of 1000.
The transactions perform the following operations:

T1: Reads the account balance (1000) and then adds 100 to it.

T2: Reads the account balance (1000) and then subtracts 50 from it.
If both transactions execute concurrently without proper control, the following could happen:

Initial balance: 1000

T1 reads balance: 1000

T2 reads balance: 1000

T1 adds 100 to balance (1000 + 100 = 1100)

T2 subtracts 50 from balance (1000 - 50 = 950)

Final balance (Incorrect): 950

In this case, the final balance is incorrect because T2 used the outdated value of the balance before
T1 updated it. To achieve serializable scheduling, the DBMS would ensure that either T1 or T2
executes first, followed by the other transaction. This way, the final balance would be consistent with
the order of execution, preserving data integrity.

Question 3
1) Attribute:

In the context of databases, an attribute refers to a characteristic or property that describes an entity
or object. Attributes are represented by columns in a database table, and they hold the actual data
values for each instance (row) of that entity. Let's explain five types of attributes with examples:

1. Single-Valued Attribute:

A single-valued attribute is an attribute that holds only one value for each instance of an entity. It
means that each record in the table has a unique value for this attribute.
Example: Consider a "Student" table with attributes like "Student_ID" (single-valued),
"Student_Name," "Age," and "Gender." Each student has a unique student ID, so "Student_ID" is a
single-valued attribute.

2. Multi-Valued Attribute:

A multi-valued attribute is an attribute that can hold multiple values for each instance of an entity. It
means that each record may have multiple values for this attribute.

Example: In the "Student" table, there might be an attribute like "Phone_Numbers," where a student
can have more than one phone number associated with them. Here, "Phone_Numbers" is a multi-
valued attribute.

3. Composite Attribute:

A composite attribute is an attribute that can be further divided into sub-attributes or components. It
represents a collection of related attributes within an entity.

Example: Consider an "Address" attribute in the "Student" table, which is composed of sub-attributes
like "Street," "City," "State," and "Zip_Code." Here, "Address" is a composite attribute.

4. Derived Attribute:

A derived attribute is an attribute that is calculated or derived from other attributes in the table. It
does not store data explicitly but is computed using the values of other attributes.

Example: In the "Student" table, we might have attributes like "Total_Marks" and "Percentage." The
"Percentage" attribute can be derived by calculating (Total_Marks / Maximum_Marks) * 100.

5. Key Attribute:

A key attribute is an attribute that uniquely identifies each record (instance) in the table. It helps in
identifying and distinguishing one record from another.

Example: In the "Student" table, "Student_ID" can be a key attribute as it uniquely identifies each
student.

2) States of a Transaction during Execution:


A database transaction goes through various states during its execution. These states are commonly
known as the ACID properties of a transaction, which ensure that the transaction is executed in a
reliable and consistent manner. The states are:

1. Active:

The transaction is said to be in the active state when it starts executing its operations. In this state,
the transaction reads and writes data from the database.

2. Partially Committed:

After the transaction has executed all its operations successfully, it enters the partially committed
state. In this state, the changes made by the transaction are not visible to other transactions yet.

3. Committed:

Once the transaction is in the committed state, it indicates that all its operations have been
successfully completed, and the changes made by the transaction are now permanently saved in the
database.

4. Failed:

If a transaction encounters an error during its execution and cannot proceed further, it enters the
failed state. In this state, any changes made by the transaction are rolled back (undone) to maintain
data consistency.

5. Aborted:

A transaction enters the aborted state when it is intentionally rolled back or canceled due to some
conflict or error. The aborted state means that the transaction is not successful, and its changes are
discarded.

3) Which of the following functional dependencies is NOT implied by the given set?

Given set of functional dependencies: { A -> B, A -> C, CD -> E, B -> D, E -> A }


Functional dependencies in the given set:

1. A -> B

2. A -> C

3. CD -> E

4. B -> D

5. E -> A

Let's check each option:

1. CD -> AC: This functional dependency is implied by the given set because we can use transitivity to
infer CD -> A from (CD -> E) and (E -> A), and then CD -> AC using (CD -> A) and (A -> C).

2. BD -> CD: This functional dependency is implied by the given set because we can use transitivity to
infer BD -> C from (BD -> D) and (D -> C).

3. BC -> CD: This functional dependency is NOT implied by the given set. We do not have any direct
or transitive dependencies involving B and C together.

4. AC -> BC: This functional dependency is implied by the given set because we can use transitivity to
infer AC -> B from (AC -> A) and (A -> B).

Therefore, the functional dependency that is NOT implied by the given set is:

3. BC -> CD

Question 4
(a) Transaction and ACID Properties:

Transaction:

In the context of databases, a transaction is a sequence of one or more database operations (such as
read, write, update, delete) that are treated as a single unit of work. The concept of transactions
ensures that all the operations within the transaction either succeed entirely or fail entirely. If any
operation in the transaction encounters an error or failure, the entire transaction is rolled back, and
the database remains unchanged. On the other hand, if all the operations in the transaction are
successful, the transaction is committed, and the changes made become permanent in the database.

Example:

Consider a banking application where a customer transfers money from one account to another. The
transaction includes two operations: debiting the amount from the source account and crediting the
same amount to the destination account. If either of these operations fails, the entire transaction
should be rolled back to maintain data consistency.

ACID Properties of a Transaction:

ACID is an acronym that represents the four essential properties that guarantee the reliability and
consistency of database transactions:

1. Atomicity:

Atomicity ensures that a transaction is treated as an indivisible unit of work. It means that all the
operations within the transaction are executed in their entirety or not executed at all. If any part of
the transaction fails, the entire transaction is rolled back, and the database returns to its initial state.

2. Consistency:

Consistency ensures that a transaction takes the database from one consistent state to another
consistent state. It ensures that the data meets all the integrity constraints and validity rules defined
in the database schema. In other words, the database remains in a valid state before and after the
transaction.

3. Isolation:

Isolation ensures that the operations of one transaction are isolated from the operations of other
transactions executing concurrently. Each transaction must execute as if it is the only transaction in
the system, even though multiple transactions may be running simultaneously. This prevents
interference and maintains data integrity.

4. Durability:

Durability guarantees that once a transaction is committed and successfully completed, its changes
become permanent and survive any subsequent failures, such as system crashes or power outages.
The committed data is stored in non-volatile storage and remains intact even if the system fails.
(b) Generalization and Specialization:

1. Generalization:

Generalization is an abstraction technique used in the Entity-Relationship (E-R) model to represent


the relationship between a higher-level entity (superclass) and one or more lower-level entities
(subclasses). It allows us to define a more generalized entity that contains common attributes and
relationships and then create specialized entities that inherit these common characteristics.

Example:

Consider an E-R diagram representing employees in an organization. We can have a general entity
called "Employee," which includes common attributes like "Employee_ID," "Name," and "Join_Date."
Then, we can create specialized entities like "Manager" and "Staff," which inherit the attributes from
the "Employee" entity and may have additional attributes specific to each subclass, such as
"Department" for Managers and "Hourly_Wage" for Staff.

52. Specialization:

Specialization is the opposite of generalization. It is the process of defining new entities (subclasses)
that have specific attributes and relationships distinct from the superclass. Specialized entities are
formed by taking a subset of the attributes and relationships from the general entity.

Example:

Following the previous example, we can specialize the "Employee" entity into "Manager" and "Staff"
entities. The "Manager" entity may have additional attributes like "Responsibilities" and
"Reports_To," while the "Staff" entity may have attributes like "Shift" and "Job_Title." These
specialized entities represent different roles within the organization with their own unique
characteristics.

(c) Purpose of E-R Diagram and Features:

The Entity-Relationship (E-R) diagram is a graphical representation used to model the database
structure and the relationships between entities in a clear and concise manner. The primary
purposes of an E-R diagram are:

1. Database Design: E-R diagrams help in the design phase of database development by providing a
visual representation of the database schema. They help to identify entities, attributes, and
relationships required to build the database.
2. Communication: E-R diagrams serve as a communication tool between developers, designers, and
stakeholders. They present a clear picture of the data model, making it easier to discuss and
understand the database structure.

3. Data Integrity: E-R diagrams aid in maintaining data integrity by visualizing the relationships
between entities and enforcing constraints like primary keys and foreign keys.

4. Query Optimization: The relationships depicted in the E-R diagram help in optimizing database
queries, as they provide insights into the data model and how different entities are related.

Features of an E-R Diagram:

An E-R diagram includes the following features:

1. Entities: Represented as rectangles, entities are objects or concepts in the real world, like
employees, customers, products, etc.

2. Attributes: Represented as ovals connected to entities, attributes are the properties or


characteristics of entities.

3. Relationships: Represented as diamonds connecting two or more entities, relationships describe


how entities are related to each other.

4. Cardinality: Indicates the number of instances of one entity that can be related to instances of
another entity in a relationship.

5. Primary Key: Highlighted in the attributes, the primary key uniquely identifies each instance of an
entity.

6. Foreign Key: Shown in attributes, foreign keys establish relationships between entities by referring
to the primary key of another entity.

Note: As an AI language model, I cannot draw diagrams directly, but I can describe how an E-R
diagram looks and the various components it includes.
Question 5

(a) Differentiate between:

1) DELETE and TRUNCATE command:

DELETE:

- The DELETE command is used to remove specific rows from a table based on a specified condition
or criteria.

- It is a Data Manipulation Language (DML) command.

- DELETE operations can be rolled back (within a transaction) if needed, and it generates individual
row-level delete operations, which may cause triggers to fire for each deleted row.

- DELETE operations are slower compared to TRUNCATE, especially for large tables, as it logs
individual deletions and maintains referential integrity constraints.

TRUNCATE:

- The TRUNCATE command is used to remove all rows from a table or a specific partition of a table.

- It is a Data Definition Language (DDL) command.

- TRUNCATE operations cannot be rolled back (no transaction), and it generates a single truncate
operation, which is faster than DELETE for clearing large tables as it deallocates the space in a more
efficient manner.

- TRUNCATE operations do not log individual deletions and do not activate triggers, which makes
them faster but less versatile than DELETE.

2) Shared and Exclusive Lock:

Shared Lock:

- A shared lock (also known as a read lock) allows multiple transactions to read a resource
simultaneously.

- It is used in situations where multiple transactions can access and read the same resource
concurrently without interfering with each other.

- However, a shared lock prevents any transaction from acquiring an exclusive lock on the same
resource until all shared locks are released.
Exclusive Lock:

- An exclusive lock (also known as a write lock) allows only one transaction to write or modify a
resource at a time.

- It is used when a transaction needs exclusive access to a resource to ensure that no other
transaction can read or write to the same resource concurrently.

- An exclusive lock prevents any other transaction, whether shared or exclusive, from accessing the
locked resource until the lock is released.

(b) Types of Database Languages:

There are primarily three types of database languages:

1. Data Definition Language (DDL):

DDL is used to define and manage the structure of the database. It includes commands to create,
modify, and delete database objects like tables, views, indexes, and constraints. Common DDL
commands include CREATE, ALTER, and DROP.

Example:

```sql

CREATE TABLE Students (

student_id INT PRIMARY KEY,

student_name VARCHAR(50),

age INT

);

```

2. Data Manipulation Language (DML):

DML is used to interact with the data stored in the database. It includes commands to insert,
retrieve, update, and delete records in the database tables. Common DML commands include
SELECT, INSERT, UPDATE, and DELETE.

Example:
```sql

INSERT INTO Students (student_id, student_name, age)

VALUES (1, 'John Doe', 25);

```

3. Data Control Language (DCL):

DCL is used to control access and permissions to the database objects. It includes commands to grant
and revoke privileges to users or roles. Common DCL commands include GRANT and REVOKE.

Example:

```sql

GRANT SELECT ON Students TO analysts;

```

(c) 2NF and 3NF with an example:

2NF (Second Normal Form):

To achieve 2NF, a table must fulfill the following conditions:

1. Be in 1NF (First Normal Form).

2. Have no partial dependencies, meaning every non-prime attribute (non-key attribute) is fully
functionally dependent on the entire primary key.

Example:

Consider a table "Student_Courses" with columns "Student_ID," "Course_ID," "Course_Name," and


"Course_Instructor." Suppose "Student_ID" is the primary key, and "Course_ID" is a non-key attribute
that is functionally dependent only on "Student_ID," not on the entire composite primary key
("Student_ID," "Course_ID").

Student_Courses:

```

Student_ID | Course_ID | Course_Name | Course_Instructor

1 | 101 | Math | Mr. Smith

1 | 102 | Science | Ms. Johnson


```

In this case, "Course_ID" is partially dependent on "Student_ID" alone, violating 2NF.

3NF (Third Normal Form):

To achieve 3NF, a table must fulfill the following conditions:

1. Be in 2NF (Second Normal Form).

2. Have no transitive dependencies, meaning no non-prime attribute depends on another non-prime


attribute.

Example (Continuing from 2NF example):

To bring the table to 3NF, we split it into two separate tables: "Students" and "Courses."

Students:

```

Student_ID | Student_Name

1 | John Doe

```

Courses:

```

Course_ID | Course_Name | Course_Instructor

101 | Math | Mr. Smith

102 | Science | Ms. Johnson

```

Now, the "Courses" table does not have any non-prime attribute (other than the primary key)
dependent on another non-prime attribute, and it satisfies 3NF. The "Students" table is already in
3NF.

You might also like