DATABASE MANAGEMENT SYSTEM
106402Unit 2: Relational Query Languages
Q1a. A row from a table is selected by - (i) selection operator - (ii) projection operator - (iii) union operator - (iv) none of these20232m
Unit 2: Relational Query Languages
View this question on its own page →A row from a table is selected by
- (i) selection operator
- (ii) projection operator
- (iii) union operator
- (iv) none of these
Worked SolutionAnswer: (i) selection operator
Explanation: In relational algebra, selection (sigma) selects rows/tuples satisfying a condition horizontally. Projection (pi) selects columns/attributes vertically. Union combines tuples from two compatible relations. So row selection is via selection operator, e.g., sigma_{age>20}(Student).
Q1b. Which of the following operations is used if we are interested in only certain columns of a table? - (i) PROJECTION (ii) SELECTION (ii) UNION (iv) JOIN20212m
Unit 2: Relational Query Languages
View this question on its own page →Which of the following operations is used if we are interested in only certain columns of a table?
- (i) PROJECTION
(ii) SELECTION
(ii) UNION
(iv) JOIN
Worked SolutionAnswer: (i) PROJECTION
Explanation: Projection (pi) operates on columns - selects specific attributes vertically, eliminating duplicates. Selection (sigma) operates on rows - selects tuples satisfying condition. Union and Join combine relations. Example: pi_{name,age}(Student) returns only name and age columns.
- (i) PROJECTION
Q1b. A normal form in which every non-prime attribute is fully dependent on prime attribute is - (i) 1 NF - (ii) 2 NF - (iii) 3 NF - (iv) BCNF20237m
Unit 2: Relational Query Languages
View this question on its own page →A normal form in which every non-prime attribute is fully dependent on prime attribute is
- (i) 1 NF
- (ii) 2 NF
- (iii) 3 NF
- (iv) BCNF
Worked SolutionAnswer: (ii) 2 NF
Explanation: 1NF - atomic values, no repeating groups.
2NF - is in 1NF and every non-prime attribute is fully functionally dependent on the primary key (no partial dependency where non-prime depends on part of composite key).
3NF eliminates transitive dependency (non-prime depends on another non-prime).
BCNF is stronger 3NF where every determinant is a superkey.The description "every non-prime attribute is fully dependent on prime attribute" actually describes 2NF partial dependency removal (taught as 2NF definition). Hence answer is 2NF. Note: strict formal definition: In 2NF, no non-prime attribute is partially dependent on any candidate key.
Q1b. __________ operations do not preserve non-matched tuples. - (i) Inner join - (ii) Left outer join - (iii) Query - (iv) Relational schema20242m
Unit 2: Relational Query Languages
View this question on its own page →__________ operations do not preserve non-matched tuples.
- (i) Inner join
- (ii) Left outer join
- (iii) Query
- (iv) Relational schema
Worked SolutionAnswer: (i) Inner join
Explanation: Inner join returns only matched tuples from both relations where join condition holds, non-matched tuples are discarded. Left outer join preserves all tuples from left relation plus matched from right, filling NULL where no match. Right/Full outer join similarly preserve non-matched. Query and Relational schema are not join operations.
Q1c. Which of the following is the original purpose of SQL? - (i) To specify the syntax and semantics of SQL data definition language (ii) To specify the syntax and semantics of SQL manipulation language (ii) To define the data structures (iv) All of the above20212m
Unit 2: Relational Query Languages
View this question on its own page →Which of the following is the original purpose of SQL?
- (i) To specify the syntax and semantics of SQL data definition language
(ii) To specify the syntax and semantics of SQL manipulation language
(ii) To define the data structures
(iv) All of the above
Worked SolutionAnswer: (iv) All of the above
Explanation: SQL was originally based on SEQUEL and intended to specify both Data Definition Language (DDL - CREATE, ALTER) and Data Manipulation Language (DML - SELECT, INSERT, etc.) syntax and semantics, and consequently data structures. In exam context, expected answer is All of the above. More precise textbook answer is (ii) SQL manipulation, but given options, (iv) is marked correct in many keys.
- (i) To specify the syntax and semantics of SQL data definition language
Q1e. BCNF stands for - (i) Boyle Cold Normalization Form - (ii) Boyce Cold Normal Form - (iii) Boyce Codd Normal Form - (iv) None of these20232m
Unit 2: Relational Query Languages
View this question on its own page →BCNF stands for
- (i) Boyle Cold Normalization Form
- (ii) Boyce Cold Normal Form
- (iii) Boyce Codd Normal Form
- (iv) None of these
Worked SolutionAnswer: (iii) Boyce Codd Normal Form
Explanation: BCNF = Boyce-Codd Normal Form (stronger than 3NF). Developed by Raymond Boyce and Edgar Codd. Condition: For every functional dependency X -> Y, X is a superkey. Options (i) and (ii) are distractors with misspelling.
Q1f. Which of the following is used at the end of the view to reject the tuples which do not satisfy the condition in where clause? - (i) With (ii) Check (iii) With check (iv) All of the above20212m
Unit 2: Relational Query Languages
View this question on its own page →Which of the following is used at the end of the view to reject the tuples which do not satisfy the condition in where clause?
- (i) With
(ii) Check
(iii) With check
(iv) All of the above
Worked SolutionAnswer: (iii) With check
Explanation: WITH CHECK OPTION at end of CREATE VIEW ensures that any INSERT/UPDATE through the view must satisfy the WHERE condition of the view, otherwise rejected. Example: CREATE VIEW v AS SELECT * FROM emp WHERE dept='CS' WITH CHECK OPTION; then INSERT dept='EE' via view fails. "With" alone or "Check" alone incomplete.
- (i) With
Q1i. The ability to query data, as well as insert, delete, and alter tuples, is offered by: - (i) TCL (Transaction Control Language) - (ii) DCL (Data Control Language) - (iii) DDL (Data Definition Language) - (iv) DML (Data Manipulation Language)20242m
Unit 2: Relational Query Languages
View this question on its own page →The ability to query data, as well as insert, delete, and alter tuples, is offered by:
- (i) TCL (Transaction Control Language)
- (ii) DCL (Data Control Language)
- (iii) DDL (Data Definition Language)
- (iv) DML (Data Manipulation Language)
Worked SolutionAnswer: (iv) DML (Data Manipulation Language)
Explanation: DML provides ability to query and modify data: SELECT, INSERT, UPDATE, DELETE. TCL is for transaction control (COMMIT, ROLLBACK), DCL for access control (GRANT, REVOKE), DDL for structure (CREATE, ALTER, DROP).
Q1j. Which join refers to join records from the right table that have no matching key in the left table and are included in the result set? - (i) Left outer join (i) Right outer join (iii) Full outer join (iv) Half outer join20212m
Unit 2: Relational Query Languages
View this question on its own page →Which join refers to join records from the right table that have no matching key in the left table and are included in the result set?
- (i) Left outer join
(i) Right outer join
(iii) Full outer join
(iv) Half outer join
Worked SolutionAnswer: (ii) Right outer join (note option list typo duplicated (i))
Explanation: Right outer join preserves all tuples from right relation, left unmatched filled with NULL, e.g., A RIGHT JOIN B. Left outer join preserves left, Full preserves both. Half outer join is not standard term. The question wording matches right outer join definition.
- (i) Left outer join
Q1j. Which command is used to remove a relation from SQL? - (i) Drop table - (ii) Delete - (iii) Purge - (iv) Remove20242m
Unit 2: Relational Query Languages
View this question on its own page →Which command is used to remove a relation from SQL?
- (i) Drop table
- (ii) Delete
- (iii) Purge
- (iv) Remove
Worked SolutionAnswer: (i) Drop table
Explanation: DROP TABLE removes relation schema and data completely from database. DELETE without WHERE deletes all rows but keeps structure (DML). PURGE is Oracle extension to permanently remove from recyclebin. REMOVE is not SQL standard.
- Install PocketlyBudget App•POCKETLY
Pocketly on Android
Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.
Q3a. Discuss about different keys used in database design with examples20247m
Unit 2: Relational Query Languages
View this question on its own page →Discuss about different keys used in database design with examples
Worked SolutionKeys in Database Design with Examples:
- Candidate Key: Minimal set uniquely identifies tuple. Example: Student {rollno}, {email} - both candidates.
- Primary Key: Chosen candidate key to uniquely identify row, cannot be NULL. Example: rollno PK for Student.
- Alternate Key: Candidate keys not chosen as primary. Example: email alternate.
- Super Key: Any superset of candidate key. Example: {rollno, name}, {rollno, email} - super keys.
- Foreign Key: Attribute in one table referencing PK of another for referential integrity. Example: Enroll(s_id) references Student(rollno).
- Composite Key: Key with multiple attributes. Example: Enroll primary key (s_id, c_id).
- Unique Key: Ensures uniqueness but allows one NULL (varies by DBMS).
- Natural vs Surrogate: Natural uses real data (rollno), Surrogate artificial (auto-increment id).
Importance: ensure entity integrity, referential integrity, normalization, indexing.
Q4b. Explain the following operations with the help of examples: - (i) Set of intersection operation (ii) Natural join operation (iii) Division operation20217m
Unit 2: Relational Query Languages
View this question on its own page →Explain the following operations with the help of examples:
- (i) Set of intersection operation
(ii) Natural join operation
(iii) Division operation
Worked SolutionRelational Algebra Operations with Examples:
(i) Set Intersection: R ∩ S returns tuples present in both relations, requires union compatibility (same arity, domain). Example: Student ∩ CricketTeam gives students who are both enrolled and in cricket team. Can be expressed as R - (R - S).
(ii) Natural Join: Combines tuples from two relations where common attributes have equal values, automatically equating and projecting out duplicate column. Example: Student(sid, name) natural join Enroll(sid, cid) returns (sid, name, cid) where sid matches, without duplicate sid. Equivalent to cross product + selection + projection on equality of common attributes.
(iii) Division: R ÷ S returns values of attributes of R not in S that are associated with all values in S. Used for "for all" queries. Example: Completed(Student, Course) ÷ Required(Course) gives students who completed all required courses. If Completed has (Amit,DBMS),(Amit,OS) and Required has (DBMS),(OS), result is Amit.
- (i) Set of intersection operation
Q4b. Write an SQL query to retrieve all employees from an "Employees" table with specific criteria (e.g., department, salary range).20247m
Unit 2: Relational Query Languages
View this question on its own page →Write an SQL query to retrieve all employees from an "Employees" table with specific criteria (e.g., department, salary range).
Worked SolutionSQL query to retrieve employees with criteria (example department='IT' and salary range 40000-60000):
SELECT * FROM Employees WHERE department = 'IT' AND salary BETWEEN 40000 AND 60000;
SELECT emp_id, name, department, salary FROM Employees WHERE department = 'Sales' AND salary > 50000 ORDER BY salary DESC;
With pattern: SELECT * FROM Employees WHERE department IN ('IT','HR') AND salary >= 40000 AND salary <= 80000;
Explain: SELECT chooses columns, WHERE filters rows, BETWEEN for range, AND combines conditions. Can add ORDER BY, LIMIT.
If parameterized: SELECT * FROM Employees WHERE department = ? AND salary BETWEEN ? AND ?;
Q5a. Define the process of database normalization and its importance in maintaining d integrity20247m
Unit 2: Relational Query Languages
View this question on its own page →Define the process of database normalization and its importance in maintaining d integrity
Worked SolutionDatabase Normalization Process and Importance:
Process: Organizes relation to minimize redundancy and anomalies via normal forms using functional dependencies.
Steps:
- 1NF: Remove repeating groups, ensure atomic values. Example: Split multivalued phone numbers into separate rows.
- 2NF: Remove partial dependency (non-prime depends on part of candidate key). Decompose.
- 3NF: Remove transitive dependency (non-prime depends on another non-prime).
- BCNF: Every determinant is superkey (stronger 3NF).
- 4NF: Remove multi-valued dependencies, 5NF join dependencies.
Importance for Data Integrity:
- Eliminates insertion anomaly (cannot insert without key), deletion anomaly (loss of data on delete), update anomaly (inconsistency).
- Reduces redundancy, saves storage, ensures consistency.
- Enforces integrity, improves query performance after proper design.
- Example: Student(Course, Instructor) unnormalized duplicates instructor per student; 3NF splits into StudentCourse and CourseInstructor ensures one instructor update suffices.
Q6a. Difference between Relational Algebra & Calculus.20247m
Unit 2: Relational Query Languages
View this question on its own page →Difference between Relational Algebra & Calculus.
Worked SolutionRelational Algebra vs Calculus:
Relational Algebra: Procedural language - specifies sequence of operations (select, project, join) to compute result. Operations on relations produce relations (closed). Example: pi_name(sigma_age>20(Student)). Implementable, defines how to get data.
Relational Calculus: Declarative/non-procedural - specifies what to retrieve using logic predicate, not how. Tuple calculus: {t | P(t)} where P is formula using quantifiers. Domain calculus similar. Example: {t.name | Student(t) AND t.age>20}. No order specified, optimizer decides.
Differences:
- Algebra procedural, calculus declarative.
- Algebra has operators; calculus has predicates, quantifiers (exists, forall).
- Both relationally complete (equivalent expressive power for safe queries), but calculus allows non-safe infinite results unless domain restricted.
- SQL borrows from both: SELECT-FROM-WHERE is calculus style but execution uses algebra.
Tuple vs Domain calculus variant distinction included.
Q8a. Find the highest normal form of a relation R(ABCD) with FD set (B→A, A→C, BC→D, AC→BE).20247m
Unit 2: Relational Query Languages
View this question on its own page →Find the highest normal form of a relation R(ABCD) with FD set
(B→A, A→C, BC→D, AC→BE).Worked SolutionFind highest normal form of R(ABCD) with FDs B->A, A->C, BC->D, AC->BE. Note E not in R - likely typo, assume R is ABCDE or FD is AC->B. Proceed with typical interpretation R(ABCD) with B->A, A->C, BC->D. Compute candidate keys:
Closure: B+ = B -> A -> C, BC -> D, so B+ = ABCD. So B is candidate key (single attribute). Also BC is superkey etc. Only B is CK.
Check 1NF: assume atomic, so 1NF.
2NF: No partial dependency because CK is single attribute B, no proper subset, so automatically 2NF.
3NF: Check each FD: B->A where B is superkey so OK. A->C where A not superkey and C non-prime -> transitive violation, so not 3NF.
Hence highest is 2NF.If considering FD AC->BE with E present and R as ABCDE: CK still B (B+= ABCDE via AC->BE gives B->AC->BE then BC->D), same violation A->C makes not 3NF, highest 2NF. If strict, R(ABCD) typo, answer remains 2NF. Mention anomaly if E included needs BCNF check fails.
Provide steps for closure, CK, normal form tests.
Q8b. A relation R(A,C,D,E,H) is having two functional dependencies sets F={A→C, AC→D, E→AD, E→H} and set G {AC→D, E→AH}, then check F and Gare equivalent or not.20247m
Unit 2: Relational Query Languages
View this question on its own page →A relation R(A,C,D,E,H) is having two functional dependencies sets F={A→C, AC→D, E→AD, E→H} and set G {AC→D, E→AH}, then check F and Gare equivalent or not.
Worked SolutionCheck if FD sets F and G equivalent over R(A,C,D,E,H):
F = {A->C, AC->D, E->AD, E->H}
G = {A->C, AC->D, E->AH}Two sets equivalent if F+= G+ (each implies the other). Check via closure.
Compute F+ check G:
- A->C in F holds (yes)
- AC->D in F holds (yes)
- E->A? In F: E+ = E -> AD -> C (via A->C) -> H (E->H), so E+ = ACDEH includes A, and AC->D gives D, so E->A and E->H hold. Also E->AD uses E->AD in F gives A and D. For G's E->AH: E->A and E->H derived above, so G subset of F+.
Compute G+ check F:
- A->C in G yes
- AC->D yes
- E->AD? Need E->A and E->D: G: E+ = E -> AH -> C (via A->C) -> D (via AC->D) => E+ = ACDEH? H via? Wait H not derived? Actually E->AH gives A and H, A->C gives C, AC->D gives D, so E->AD holds (A and D). So E->AD in G+.
- E->H in G via E->AH gives H, yes.
Thus every FD in F is implied by G and vice versa, so F+ = G+ => equivalent.
Formally F covers G and G covers F via Armstrong axioms. Hence equivalent.
Provide closure tables to demonstrate.
Q9b. Describe the importance of data integrity in a database. How can constraints (such as primary keys and foreign keys) help enforce integrity?20247m
Unit 2: Relational Query Languages
View this question on its own page →Describe the importance of data integrity in a database. How can constraints (such as primary keys and foreign keys) help enforce integrity?
Worked SolutionImportance of Data Integrity and Constraints:
Data Integrity ensures accuracy, consistency, reliability of data - prevents invalid entries, maintains business rules. Without integrity, database contains garbage, queries wrong, application fails.
Constraints enforce integrity declaratively:
Primary Key (Entity Integrity): Uniquely identifies row, prevents duplicates/NULL. Example: Student rollno PK ensures no duplicate student.
Foreign Key (Referential Integrity): Ensures reference exists or NULL, prevents orphan. Example: Enroll(s_id) FK references Student, cannot enroll non-existent student, cascade delete maintains.
NOT NULL, UNIQUE, CHECK, DEFAULT, Domain constraints: Enforce valid ranges, e.g., CHECK (age>0), salary >0.
Benefits: Centralized enforcement, not reliant on app code, prevents anomalies, automatic validation, easier maintenance. Example without PK, duplicate inserts cause inconsistency.