Database Management System (1333204) - Summer 2024 Solution

Solution guide for Database Management System (1333204) Summer 2024 exam

Question 1(a) [3 marks]

Define: DBMS, Instance, Metadata

Answer:

  • DBMS (Database Management System): Software that enables users to create, maintain, and access databases by controlling data organization, storage, retrieval, security, and integrity.
  • Instance: The actual data stored in a database at a particular moment in time. It's the current state or snapshot of a database.
  • Metadata: Data about data that describes database structure, including tables, fields, relationships, constraints, and indexes.

Mnemonic: "DIM view" - Database system, Instance snapshot, Metadata description

Question 1(b) [4 marks]

Define and Explain with example: 1.Entity 2. Attribute

Answer:

Table: Entity vs Attribute

ConceptDefinitionExample
EntityA real-world object or concept that can be distinctly identifiedStudent (John), Book (Harry Potter), Car (Toyota Camry)
AttributeCharacteristic or property that describes an entityStudent: roll_no, name, address
Book: ISBN, title, author

Diagram:

Mnemonic: "EA-PC" - Entities Are Physical/Conceptual, Attributes Provide Characteristics

Question 1(c) [7 marks]

Write the full form of DBA. Explain the roles and responsibilities of DBA.

Answer:

DBA stands for Database Administrator.

Table: DBA Responsibilities

RoleDescription
Database DesignCreates logical/physical database structure and schema
Security ManagementControls access through user accounts and permissions
Performance TuningOptimizes queries, indexes for faster data retrieval
Backup & RecoveryImplements strategies to prevent data loss
MaintenanceUpdates software, applies patches, monitors space

Diagram:

Mnemonic: "SPMBU" - Security, Performance, Maintenance, Backup, Updates

Question 1(c) OR [7 marks]

Explain relational and network data models in detail.

Answer:

Table: Relational vs Network Data Models

FeatureRelational ModelNetwork Model
StructureTables (relations) with rows and columnsRecords connected by pointers forming complex networks
RelationshipRelated through primary & foreign keysDirect links between parent-child records
FlexibilityHigh - tables can be joined as neededLimited - predefined physical connections
ExamplesMySQL, Oracle, SQL ServerIDS, IDMS
Query LanguageSQL (structured query language)Procedural languages

Diagram:

Mnemonic: "RSPEN" - Relational uses Sets, Pointers Enable Networks

Question 2(a) [3 marks]

Draw figure and Explain Generalization.

Answer:

Generalization: The process of extracting common characteristics from two or more entities to create a new higher-level entity.

Diagram:

Mnemonic: "BUSH" - Bottom-Up Shared Hierarchy

Question 2(b) [4 marks]

Explain Primary Key and Foreign Key Constraints.

Answer:

Table: Primary Key vs Foreign Key

ConstraintDefinitionPropertiesExample
Primary KeyUniquely identifies each record in a tableUnique, Not Null, Only one per tableStudentID in Students table
Foreign KeyLinks data between tables, references a primary key in another tableCan be NULL, Multiple allowed per tableDeptID in Employees table referencing Departments table

Diagram:

Mnemonic: "PURE FIRE" - Primary Uniquely References Entities, Foreign Imports Referenced Entities

Question 2(c) [7 marks]

Construct an E-R diagram for Hospital Management System.

Answer:

E-R Diagram for Hospital Management System:

Mnemonic: "PADRE" - Patients Appointments Doctors Rooms Entities

Question 2(a) OR [3 marks]

Draw figure and Explain Specialization.

Answer:

Specialization: The process of creating new entities from an existing entity by adding unique attributes to distinguish them.

Diagram:

Mnemonic: "TDSB" - Top-Down Specialized Breakdown

Question 2(b) OR [4 marks]

Explain single valued v/s multi-valued attributes with suitable examples.

Answer:

Table: Single-valued vs Multi-valued Attributes

TypeDefinitionExampleImplementation
Single-valuedContains only one value for each entity instancePerson's birth date, SSNDirectly stored in table columns
Multi-valuedCan have multiple values for the same entityPerson's skills, phone numbersSeparate table or specialized formats

Diagram:

Mnemonic: "SOME" - Single One, Multiple Entries

Question 2(c) OR [7 marks]

Construct an E-R diagram for Banking Management System.

Answer:

E-R Diagram for Banking Management System:

Mnemonic: "CABLE" - Customers Accounts Branches Loans Employees

Question 3(a) [3 marks]

Explain WHERE and DESC clause with example.

Answer:

Table: WHERE and DESC Clauses

ClausePurposeSyntaxExample
WHEREFilters rows based on specified conditionSELECT columns FROM table WHERE conditionSELECT * FROM employees WHERE salary > 50000
DESCSorts results in descending orderSELECT columns FROM table ORDER BY column DESCSELECT * FROM products ORDER BY price DESC

Diagram:

SQL

Mnemonic: "WDF" - Where filters Data, DESC orders First-highest

Question 3(b) [4 marks]

List DDL commands. Explain any two DDL commands with examples.

Answer:

DDL (Data Definition Language) Commands:

  1. CREATE
  2. ALTER
  3. DROP
  4. TRUNCATE
  5. RENAME

Table: CREATE and ALTER Commands

CommandPurposeSyntaxExample
CREATECreates database objects like tables, views, indexesCREATE TABLE table_name (column definitions)CREATE TABLE students (id INT PRIMARY KEY, name VARCHAR(50))
ALTERModifies structure of existing database objectsALTER TABLE table_name actionALTER TABLE students ADD COLUMN email VARCHAR(100)

CodeBlock:

SQL

Mnemonic: "CADTR" - Create Alter Drop Truncate Rename

Question 3(c) [7 marks]

Perform the following Query on the table "Company" having the field's eno, ename, salary, dept in SQL. 1. Display all records in Company table. 2. Display only dept without duplicate value. 3. Display all records sorted in descending order of ename. 4. Add one new column "cityname" to store city. 5. Display name of all employees who do not stay in city "Mumbai". 6. Delete all employees having salary less than 10,000. 7. Display the employee names starts with "A".

Answer:

CodeBlock:

SQL

Table: SQL Operations

OperationSQL CommandPurpose
SELECTSELECT * FROM CompanyRetrieve all data
DISTINCTSELECT DISTINCT deptRemove duplicates
ORDER BYORDER BY ename DESCSort in descending
ALTERALTER TABLE ADD COLUMNAdd new column
WHEREWHERE cityname != 'Mumbai'Filter condition
DELETEDELETE FROM WHERERemove records
LIKEWHERE ename LIKE 'A%'Pattern matching

Mnemonic: "SODA-WDL" - Select Order Distinct Alter - Where Delete Like

Question 3(a) OR [3 marks]

Explain SELECT and DISTINCT clause with example.

Answer:

Table: SELECT and DISTINCT Clauses

ClausePurposeSyntaxExample
SELECTRetrieves data from databaseSELECT columns FROM tableSELECT name, age FROM students
DISTINCTEliminates duplicate valuesSELECT DISTINCT columns FROM tableSELECT DISTINCT department FROM employees

Diagram:

SQL

Mnemonic: "SUD" - Select Unique with Distinct

Question 3(b) OR [4 marks]

List DML commands. Explain any two DML commands with examples.

Answer:

DML (Data Manipulation Language) Commands:

  1. INSERT
  2. UPDATE
  3. DELETE
  4. SELECT

Table: INSERT and UPDATE Commands

CommandPurposeSyntaxExample
INSERTAdds new records to a tableINSERT INTO table_name VALUES (values)INSERT INTO students VALUES (1, 'John', 85)
UPDATEModifies existing recordsUPDATE table_name SET column=value WHERE conditionUPDATE students SET marks=90 WHERE id=1

CodeBlock:

SQL

Mnemonic: "IUDS" - Insert Update Delete Select

Question 3(c) OR [7 marks]

Write the Output of Following Query. 1. ABS(-34),ABS(16) 2. SQRT(16),SQRT(64) 3. POWER(5,2), POWER(2,4) 4. MOD(15,3), MOD(13,3) 5. ROUND(123.456,1), ROUND(123.456,2) 6. CEIL(122.6), CEIL(-122.6) 7. FLOOR(-157.5),FLOOR(157.5)

Answer:

Table: SQL Function Outputs

FunctionDescriptionOutput
ABS(-34),ABS(16)Absolute value34, 16
SQRT(16),SQRT(64)Square root4, 8
POWER(5,2), POWER(2,4)Power function25, 16
MOD(15,3), MOD(13,3)Modulus (remainder)0, 1
ROUND(123.456,1), ROUND(123.456,2)Round to decimal places123.5, 123.46
CEIL(122.6), CEIL(-122.6)Round up to nearest integer123, -122
FLOOR(-157.5),FLOOR(157.5)Round down to nearest integer-158, 157

Diagram:

Mnemonic: "ASPRCF" - Absolute Square Power Remainder Ceiling Floor

Question 4(a) [3 marks]

List data types in SQL. Explain 1.VARCHAR() and 2.INT() data types with example.

Answer:

SQL Data Types Categories:

  1. Numeric (INT, FLOAT, DECIMAL)
  2. Character (CHAR, VARCHAR)
  3. Date/Time (DATE, TIME, DATETIME)
  4. Binary (BLOB, BINARY)
  5. Boolean (BOOL)

Table: VARCHAR and INT Data Types

Data TypeDescriptionSizeExample
VARCHAR(n)Variable-length character stringUp to n characters, only uses needed spaceVARCHAR(50) for names, emails
INTInteger numeric dataUsually 4 bytes, -2,147,483,648 to 2,147,483,647INT for IDs, counts, ages

CodeBlock:

SQL

Mnemonic: "VIA" - Variable strings, Integers for Ages

Question 4(b) [4 marks]

Explain 2NF (Second Normal Form) with example and solution.

Answer:

2NF Definition: A relation is in 2NF if it is in 1NF and no non-prime attribute is dependent on any proper subset of any candidate key.

Table: Before 2NF

student_idcourse_idcourse_nameinstructor
S1C1DatabaseProf. Smith
S1C2NetworkingProf. Jones
S2C1DatabaseProf. Smith
S3C3ProgrammingProf. Wilson

Problem: Non-prime attributes (course_name, instructor) depend only on course_id, not the entire key (student_id, course_id).

Diagram: 2NF Solution

Table: After 2NF Enrollment Table:

student_idcourse_id
S1C1
S1C2
S2C1
S3C3

Course Table:

course_idcourse_nameinstructor
C1DatabaseProf. Smith
C2NetworkingProf. Jones
C3ProgrammingProf. Wilson

Mnemonic: "PFPK" - Partial Functional dependency on Primary Key

Question 4(c) [7 marks]

Explain function dependency. Explain Partial function dependency with example.

Answer:

Functional Dependency: Relationship between attributes where one attribute's value determines another attribute's value.

Notation: X → Y (X determines Y)

Partial Functional Dependency: When a non-prime attribute depends on part of a composite key rather than the whole key.

Table: Order Details (Before Normalization)

order_idproduct_idquantityproduct_nameprice
O1P15Keyboard50
O1P22Mouse25
O2P11Keyboard50
O3P33Monitor200

Functional Dependencies:

  • (order_id, product_id) → quantity
  • product_id → product_name
  • product_id → price

Diagram:

Solution (Normalized Tables): Orders Table:

order_idproduct_idquantity
O1P15
O1P22
O2P11
O3P33

Products Table:

product_idproduct_nameprice
P1Keyboard50
P2Mouse25
P3Monitor200

Mnemonic: "PDPK" - Partial Dependency on Part of Key

Question 4(a) OR [3 marks]

Explain commands: 1) To_Char() 2) To_Date()

Answer:

Table: Conversion Functions

FunctionPurposeSyntaxExample
TO_CHAR()Converts date/number to character string using format modelTO_CHAR(value, [format])TO_CHAR(SYSDATE, 'DD-MON-YYYY') → '14-JUN-2024'
TO_DATE()Converts character string to date using format modelTO_DATE(string, [format])TO_DATE('14-JUN-2024', 'DD-MON-YYYY') → date value

CodeBlock:

SQL

Mnemonic: "DCS" - Date Conversion Strings

Question 4(b) OR [4 marks]

Explain Full function dependency with example.

Answer:

Full Functional Dependency: When an attribute is functionally dependent on a composite key, and dependent on the entire key, not just part of it.

Table: Exam Results

student_idcourse_idexam_datescore
S1C12024-05-1085
S1C22024-05-1592
S2C12024-05-1078
S2C22024-05-1588

Full Functional Dependency:

  • (student_id, course_id) → score (score depends on both student and course)

Diagram:

Explanation: The score attribute fully depends on the composite key (student_id, course_id) because:

  • Different students can have different scores for the same course
  • Same student can have different scores for different courses
  • We need both student_id and course_id to determine a specific score

Mnemonic: "FCEK" - Fully dependent on Complete/Entire Key

Question 4(c) OR [7 marks]

Define normalization. Explain 1NF (First Normal Form) with example and solution.

Answer:

Normalization: Process of organizing data to minimize redundancy, improve data integrity, and eliminate anomalies by dividing larger tables into smaller related tables.

1NF Definition: A relation is in 1NF if all attributes contain atomic (indivisible) values only.

Table: Before 1NF

student_idnamecourses
S1JohnMath, Physics
S2MaryChemistry, Biology, Physics
S3TimComputer Science

Problems:

  • Non-atomic values (multiple courses per cell)
  • Cannot easily query or update specific courses

Diagram:

Table: After 1NF

student_idnamecourse
S1JohnMath
S1JohnPhysics
S2MaryChemistry
S2MaryBiology
S2MaryPhysics
S3TimComputer Science

Mnemonic: "ASAV" - Atomic Single-value Attributes only Valid

Question 5(a) [3 marks]

Explain the concept of Transaction with example.

Answer:

Transaction: A logical unit of work that must be either completely executed or completely undone.

Table: Transaction Properties

PropertyDescription
AtomicityAll operations complete successfully or none do
ConsistencyDatabase remains in consistent state before and after transaction
IsolationConcurrent transactions don't interfere with each other
DurabilityCompleted transactions persist even after system failures

Example:

SQL

Mnemonic: "ACID" - Atomicity Consistency Isolation Durability

Question 5(b) [4 marks]

Explain equi join with syntax and example.

Answer:

Equi Join: A join that uses equality comparison operator to match records from two or more tables based on a common field.

Syntax:

SQL

Table Example: Employees Table:

emp_idnamedept_id
101Alice1
102Bob2
103Carol1

Departments Table:

dept_iddept_namelocation
1HRNew York
2ITChicago
3FinanceBoston

CodeBlock:

SQL

Result:

namedept_namelocation
AliceHRNew York
BobITChicago
CarolHRNew York

Diagram:

Mnemonic: "MEET" - Match Equal Elements Every Table

Question 5(c) [7 marks]

Explain Conflict Serializability in detail.

Answer:

Conflict Serializability: A way to ensure correctness of concurrent transactions by guaranteeing that the execution schedule is equivalent to some serial execution.

Table: Key Concepts in Conflict Serializability

ConceptDescription
Conflicting OperationsTwo operations conflict if they access same data item and at least one is a write
Precedence GraphDirected graph showing conflicts between transactions
Conflict SerializableSchedule is conflict serializable if its precedence graph is acyclic

Diagram:

Example: Consider transactions T1 and T2:

  • T1: Read(A), Write(A)
  • T2: Read(A), Write(A)

Schedule S1: R1(A), W1(A), R2(A), W2(A) - Serializable (equivalent to T1→T2) Schedule S2: R1(A), R2(A), W1(A), W2(A) - Not serializable (contains cycle in precedence graph)

Steps to Determine Conflict Serializability:

  1. Identify all pairs of conflicting operations
  2. Construct the precedence graph
  3. Check if the graph has cycles
  4. If no cycles, the schedule is conflict serializable

Mnemonic: "COPS" - Conflicts, Operations, Precedence, Serializability

Question 5(a) OR [3 marks]

Explain the properties of Transaction with example.

Answer:

ACID Properties of Transactions:

Table: ACID Properties

PropertyDescriptionExample
AtomicityAll operations complete successfully or none doBank transfer - both debit and credit must succeed or fail together
ConsistencyDatabase must be in a consistent state before and after transactionAfter transferring $100, total money in system remains unchanged
IsolationConcurrent transactions don't interfere with each otherTransaction A doesn't see partial results of Transaction B
DurabilityOnce committed, changes are permanentPower failure won't cause committed transaction to be lost

Diagram:

Example:

SQL

Mnemonic: "ACID" - Atomicity Consistency Isolation Durability

Question 5(b) OR [4 marks]

Write the Queries using set operators to find following using given "Faculty" and "CT" tables. 1. List the name of the persons who are either a Faculty or a CT. 2. List the name of the persons who are a Faculty as well as a CT. 3. List the name of the persons who are only a Faculty and not a CT. 4. List the name of the persons who are only a CT and not a Faculty.

Answer:

Table Data: Faculty Table:

FacultyNameErNoDept
PrakashFC01ICT
RonakFC02IT
RakeshFC03EC
KinjalFC04ICT

CT (Class Teacher) Table:

DeptCTName
ECRakesh
CEJigar
ICTPrakash
ITGunjan

CodeBlock:

SQL

Diagram:

Results:

  1. UNION: Prakash, Ronak, Rakesh, Kinjal, Jigar, Gunjan
  2. INTERSECT: Prakash, Rakesh
  3. MINUS (Faculty - CT): Ronak, Kinjal
  4. MINUS (CT - Faculty): Jigar, Gunjan

Mnemonic: "UIMM" - Union Intersect Minus Minus

Question 5(c) OR [7 marks]

Explain View Serializability in detail.

Answer:

View Serializability: A schedule is view serializable if it is view equivalent to some serial schedule, meaning it produces the same "view" (or final state) of the database.

Table: Comparison with Conflict Serializability

AspectView SerializabilityConflict Serializability
DefinitionBased on the final results of reads and writesBased on conflicts between operations
ConditionPreserves initial read, final write, and read-write dependencyPreserves all conflicts between operations
ScopeBroader class of schedulesSubset of view serializable schedules
TestingMore complex to testCan test with precedence graph

Diagram:

View Equivalence Conditions:

  1. Initial Reads: If T1 reads an initial value of data item A in schedule S1, it must also read the initial value in S2.
  2. Final Writes: If T1 performs the final write on data item A in S1, it must also perform the final write in S2.
  3. Read-Write Dependency: If T1 reads a value of A written by T2 in S1, it must also read the value written by T2 in S2.

Example of View Serializable but not Conflict Serializable Schedule: Consider transactions with blind writes (writes without reading):

  • T1: W1(A)
  • T2: W2(A)

Schedule S: W1(A), W2(A) - View serializable to both T1→T2 and T2→T1 (final write is always T2) But W1(A) and W2(A) conflict, so a conflict graph would have an edge in both directions.

Mnemonic: "IRF" - Initial reads, Result writes, Final view