0% found this document useful (0 votes)
2 views

DBMD and UHV assignment solution

DBMD Asignment for GGSIPU BTech IT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DBMD and UHV assignment solution

DBMD Asignment for GGSIPU BTech IT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DBMD

Assignment 1

1. Sequential Access vs. Direct Access (2 Marks)

Feature Sequential Access Direct Access


Access Method Reads data in order Accesses any data directly
Speed Slower for large data Faster retrieval
Example Tape storage Hard disk, SSD
Application Log processing Database indexing

2. Model vs. Data Model (2 Marks)

Aspect Model Data Model


Definition Abstract representation of a system Defines structure and relationships of data
Example UML Model Relational Model, ER Model

3. Existence Dependency vs. Identification Dependency (2 Marks)

 Existence Dependency: An entity cannot exist without another entity.


o Example: Employee must belong to a Department.
 Identification Dependency: A weak entity requires a strong entity’s key as part of its
identifier.
o Example: OrderItem needs OrderID to exist.

4. Participation Constraint & Minimum Cardinality Constraint (2 Marks)

 Participation Constraint: Determines if all instances of an entity must participate in


a relationship.
o Example: Every Student must be Enrolled in a course (Total Participation).
 Minimum Cardinality Constraint: Specifies the least number of relationships an
entity must have.
o Example: A Customer must have at least one Order.

5. Business Rules Not Reflected in ER Diagram (5 Marks)

1. Data Validation Rules – Example: Email format validation.


2. Security Rules – Example: Admin access to sensitive data.
3. Workflow Rules – Example: An order can’t be processed before payment
confirmation.
4. Temporal Constraints – Example: A refund is valid only within 30 days.
5. Business Calculations – Example: Automatic discount calculations.

6. Inclusive vs. Exclusive Arc (2 Marks)

 Inclusive Arc (OR Relationship): An entity can be related to multiple subtypes.


o Example: A Vehicle can be a Car and Truck.
 Exclusive Arc (XOR Relationship): An entity belongs to only one subtype at a time.
o Example: A Person can be either an Employee or a Student, not both.

7. ERD vs. EERD & Hospital Management System Diagram (10 Marks)

Feature ERD EERD


Basic entity-relationship
Definition Extended with inheritance, categories
representation
Generalization, specialization,
Includes Entities, relationships
aggregation
ERD for hospital with Patient, EERD with specialized Doctor types
Example
Doctor, Appointment (Surgeon, Physician)

Hospital Management System EERD Includes:


Assignment 2

Here are the concise answers with 5-7 key points for each 5-mark question:

Q5. Logical Schema Using Directed Arcs & Inclusion Dependencies

1. A logical schema represents database relationships using foreign keys and inclusion
dependencies.
2. Directed arcs indicate foreign key constraints, ensuring data consistency.
3. Example: Employee(DeptID) → Department(DeptID), enforcing referential integrity.
4. Inclusion dependency: Ensures that values in one table must exist in another.
5. Benefits: Reduces redundancy, improves retrieval, maintains consistency.
6. Drawback: Complex queries due to multiple joins.
7. Cross-referencing approach is used for many-to-many relationships via
intermediate tables.

1. Relation Schema and Differences (2 Marks)

 A relation schema defines the structure of a relation (table) with attributes.


 Relation: A set of tuples (rows) that follow a schema.
 Relational Schema: A collection of relation schemas in a database.

2. Referential Integrity Constraint (2 Marks)

 Ensures foreign key values in a table must reference existing values in another table.
 Importance: Maintains data consistency and prevents orphan records.
 Foreign Key: An attribute in one table that refers to the primary key in another.

3. Information Preservation in Data Model Mapping (2 Marks)

 Ensures that data transformation between models (ER to relational) does not lose
information.
 Key concept: Every entity, relationship, and constraint must be representable in the
target model.
6. Purpose of Normalization (2 Marks)

 Reduces redundancy and avoids anomalies.


 Ensures data integrity through decomposition.

7. Loss-Join vs. Lossless-Join Decomposition (2 Marks)

 Loss-Join: Information is lost after decomposition.


 Lossless-Join: No information is lost after decomposition (ideal case).

Q8. Normalization of FLIGHT Relation (5 Marks)

(a) Candidate Key(s):

 The candidate key must determine all attributes in the relation.


 {Airport, Flight#, Date} is a candidate key because:
o It determines Gate# (fd1).
o It indirectly determines Aircraft (fd2) and Pilot (fd3).

(b) Normal Form Violation:

 1NF is satisfied (all values are atomic).


 2NF violation: Flight#, Date → Aircraft (fd2) and Flight#, Date → Pilot (fd3) create
partial dependency on part of the candidate key.
 3NF violation: If we remove a non-prime attribute (Aircraft or Pilot), functional
dependencies will be lost.
 BCNF violation: fd2 and fd3 have determinants (Flight#, Date) that are not
superkeys, violating BCNF.

(c) BCNF Decomposition (Lossless-Join)

To achieve BCNF, we decompose FLIGHT into:

1. FLIGHT_DETAILS (Flight#, Date, Airport, Gate#)


2. FLIGHT_AIRCRAFT (Flight#, Date, Aircraft)
3. FLIGHT_PILOT (Flight#, Date, Pilot)

This decomposition ensures no redundancy and lossless-join properties.

(d) Functional Dependency Preservation

 fd2 (Flight#, Date → Aircraft) and fd3 (Flight#, Date → Pilot) are preserved in
separate tables.
 fd1 (Airport, Flight#, Date → Gate#) remains intact in FLIGHT_DETAILS.
 All dependencies are preserved, so dependency preservation is maintained.
Q9. Multi-Valued Dependency & 4NF in STUDENT Relation (5 Marks)

(a) Does STUDENT have a Multi-Valued Dependency (MVD)?

 Here, Sid → Shoe_size and Sid → Marital_status, but they are not independent;
o Shoe_size is a physical characteristic,
o Marital_status is a life event.
 No multi-valued dependency exists because Shoe_size and Marital_status are not
independent but functionally dependent on Sid.

(b) Does STUDENT have a 4NF violation?

 4NF states that a table should not contain independent multi-valued


dependencies.
 Since there is no MVD, STUDENT is already in 4NF, and no decomposition is
needed.
 Conclusion: No 4NF violation because all dependencies are functional
dependencies, not MVDs.

Assignment 3

Q1: Difference Between COUNT(*) and COUNT(column_name) (5 Marks)

(a) COUNT(*) vs. COUNT(column_name)

1. COUNT(*) counts all rows in a table, including NULL values.


2. COUNT(column_name) counts only non-NULL values in the specified column.

(b) COUNT(column_name) vs. COUNT(DISTINCT column_name)

1. COUNT(column_name) counts all non-null values, including duplicates.


2. COUNT(DISTINCT column_name) counts only unique non-null values in a
column.

Example:

SELECT COUNT(*) FROM Employees; -- Counts all rows


SELECT COUNT(Salary) FROM Employees; -- Counts non-null salaries
SELECT COUNT(DISTINCT Salary) FROM Employees; -- Counts unique non-null
salaries

Q2: Join Operations (5 Marks)

(a) What is a Join?

A JOIN operation in SQL combines rows from two or more tables based on a related
column.
(b) Join Compatibility

Two tables are join-compatible if they have a common attribute with the same data type.

(c) Inner Join vs. Outer Join

 INNER JOIN: Returns only matching rows from both tables.


 OUTER JOIN: Returns all rows from one table and matching rows from the other.
o LEFT OUTER JOIN: All rows from the left table + matching rows from the
right.
o RIGHT OUTER JOIN: All rows from the right table + matching rows from
the left.
o FULL OUTER JOIN: All rows from both tables (NULL for unmatched
values).

Example:

SELECT e.EmployeeID, e.Name, d.DepartmentName


FROM Employees e
INNER JOIN Departments d
ON e.DeptID = d.DeptID;

Q3: When to Use GROUP BY Clause? (3 Marks)

1. When aggregating data using COUNT, SUM, AVG, MIN, MAX.


2. When grouping results based on one or more columns.
3. When using HAVING to filter grouped results.

Example:

SELECT Department, AVG(Salary)


FROM Employees
GROUP BY Department;

Q4: What is a Subquery? (2 Marks)

A subquery is a query inside another SQL query.

Where Can Subqueries Appear?

1. SELECT Clause: SELECT (subquery) FROM Table;


2. FROM Clause: SELECT * FROM (subquery) AS alias;
3. WHERE Clause: SELECT * FROM Employees WHERE Salary > (subquery);

Example:

SELECT Name
FROM Employees
WHERE Salary > (SELECT AVG(Salary) FROM Employees);
Q5: SQL Schema & ALTER TABLE Statements (5 Marks)

(a) CREATE TABLE Statements

CREATE TABLE PATIENT (


PatientID INT PRIMARY KEY,
Name VARCHAR(100),
Age INT,
Occupation VARCHAR(50)
);

CREATE TABLE MEDICATION (


MedID INT PRIMARY KEY,
Name VARCHAR(100),
Dosage VARCHAR(50),
ListPrice DECIMAL(10,2)
);

(b) Add unit_cost to MEDICATION Table

ALTER TABLE MEDICATION


ADD unit_cost DECIMAL(10,2) CHECK (unit_cost BETWEEN 0.50 AND 7.50);

(c) Enforce Business Rule (List Price ≥ 20% Higher than Unit Cost)

ALTER TABLE MEDICATION


ADD CHECK (ListPrice >= 1.2 * unit_cost);

(d) Drop Occupation from PATIENT Table

ALTER TABLE PATIENT


DROP COLUMN Occupation;

Q6: Difference Between Cursors, Functions, and Procedures (5 Marks)

Feature Cursors Functions Procedures


Return a single value or
Purpose Fetch records row-by-row Execute business logic
table
Nothing (or OUT
Returns Row(s) Value or Table
parameters)
Called
Loops, Stored Procedures SELECT, WHERE EXEC command
In
DECLARE cursor_name CREATE FUNCTION CREATE PROCEDURE
Example CURSOR FOR SELECT * getSalary() RETURNS updateSalary() AS
FROM Employees; DECIMAL AS ... BEGIN ... END;

Example: Cursor

DECLARE employee_cursor CURSOR FOR


SELECT Name FROM Employees;
Example: Function

CREATE FUNCTION getTotalSalary() RETURNS DECIMAL AS


BEGIN
RETURN (SELECT SUM(Salary) FROM Employees);
END;

Example: Procedure

CREATE PROCEDURE updateSalary()


AS
BEGIN
UPDATE Employees SET Salary = Salary * 1.1;
END;

UHV

Assignment 1

Q1: What do you mean by value education? Why is there a need for value
education? (10 Marks)

Meaning of Value Education:

Value education refers to the process of instilling moral, ethical, and social values in
individuals to help them become responsible, compassionate, and well-rounded citizens. It
involves learning about honesty, integrity, respect, empathy, and other essential human
values.

Need for Value Education:

1. Moral Development: Helps individuals differentiate between right and wrong,


promoting ethical decision-making.
2. Character Building: Encourages discipline, responsibility, and integrity, shaping a
strong personality.
3. Promotes Social Harmony: Teaches respect for diversity, fostering unity and
peaceful coexistence.
4. Enhances Emotional Intelligence: Helps in understanding and managing emotions
effectively.
5. Guides Towards a Meaningful Life: Encourages self-awareness, self-discipline, and
purpose-driven actions.
6. Prepares for Ethical Leadership: Ensures responsible behavior in personal, social,
and professional life.
7. Reduces Social Problems: Helps in addressing issues like corruption, violence, and
discrimination.
8. Develops Responsible Citizenship: Encourages civic responsibility and active
participation in society.
9. Enhances Decision-Making Abilities: Helps individuals make ethical choices in
difficult situations.
10. Supports Sustainable Development: Encourages respect for the environment and
future generations.
Q2: What are the basic guidelines for value education? (5 Marks)

1. Universal and Rational: Value education should be applicable to all individuals,


irrespective of religion, culture, or background.
2. Human-Centric Approach: Focuses on human well-being, self-development, and
relationships.
3. Harmony with Nature: Encourages sustainable living and respect for the
environment.
4. Socially Responsible: Helps individuals contribute positively to society.
5. Experiential Learning: Values should be practiced in real-life situations, not just
theoretically understood.

Q3: How does value education help in fulfilling one’s aspirations? (5 Marks)

1. Clarity of Goals: Helps individuals define what they truly want in life, beyond
materialistic desires.
2. Self-Awareness: Encourages introspection, leading to better decision-making.
3. Balanced Life Approach: Promotes harmony between personal, social, and
professional aspirations.
4. Ethical Success: Ensures that success is achieved with integrity and honesty.
5. Satisfaction and Happiness: Helps individuals attain inner peace and long-term
fulfillment.

You might also like