CS312 – Mobile Application Development: Midterm Important Subjective (26 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS312 Course Page · CS312 MCQ Pack (23 MCQs)
-
What is a database? How does a DBMS help in managing a database?
Topic: Database Basics & Data Independence • 2 marks marks
A database is an organized collection of related data that is stored so it can be easily accessed, managed and updated. A Database Management System (DBMS) is the software that sits between the users/applications and the database: it lets users define the structure of the data, insert, retrieve, update and delete data, and it enforces security, integrity and concurrent access. Examples of DBMS software are Oracle, MySQL, MS SQL Server and MS Access.
-
"A database must be independent of the application that uses it." Explain the concept of data independence and differentiate between physical and logical data independence.
Topic: Database Basics & Data Independence • 5 marks marks
Data independence is the ability to change the schema at one level of a database system without having to change the schema at the next higher level. Because of it, the database stays independent of the particular application programs that use it — the applications keep working even when the stored structure is modified. 1. Physical data independence: the capacity to change the internal (physical) schema — e.g. file organization, storage devices or access paths such as indexes — without changing the conceptual schema or the application programs. 2. Logical data independence: the capacity to change the conceptual schema — e.g. adding a new attribute or a new entity type — without changing the external schemas (views) or the application programs. Logical data independence is harder to achieve than physical data independence, because application programs depend heavily on the logical structure of the data.
-
Write any three advantages of using a database management system (DBMS) over a traditional file-processing system.
Topic: Database Basics & Data Independence • 3 marks marks
1. Reduced data redundancy: data is stored in a controlled, integrated way, so the same fact is not duplicated in many files. 2. Data integrity and consistency: integrity constraints (such as primary key–foreign key rules) are enforced centrally, so inconsistent copies do not arise. 3. Data sharing and security: many users and applications can share the same data, while the DBMS controls who may access or modify which data through authorization (GRANT/REVOKE). (Other valid advantages: data independence, backup and recovery, and concurrent access control.)
-
What is a key in a relational database? Why are keys needed?
Topic: Keys in the Relational Model • 2 marks marks
A key is an attribute (or a set of attributes) whose value can be used to identify tuples (rows) of a relation. Keys are needed to (i) uniquely identify each record in a table, (ii) establish relationships between tables through primary key–foreign key links, and (iii) enforce integrity constraints so that duplicate or invalid records cannot be stored.
-
Define super key and candidate key. How does a candidate key differ from a super key?
Topic: Keys in the Relational Model • 3 marks marks
A super key is a set of one or more attributes that can uniquely identify a tuple in a relation; a super key may contain extra attributes that are not needed for unique identification. A candidate key is a minimal super key — a super key from which no attribute can be removed without losing the unique-identification property. Difference: every candidate key is a super key, but not every super key is a candidate key, because a super key may contain unnecessary (redundant) attributes. For example, in a Student table, {RegNo} is a candidate key, while {RegNo, Name} is only a super key.
-
Define primary key and list its important properties.
Topic: Keys in the Relational Model • 3 marks marks
A primary key is the candidate key chosen by the database designer to uniquely identify tuples in a relation; a table can have only one primary key. Its properties are: 1. Uniqueness: no two tuples can have the same primary key value. 2. NOT NULL: a primary key attribute can never contain a NULL value (entity integrity rule). 3. It should be minimal and, preferably, stable (its value should not change over time). Example: RegNo in a Student table.
-
What is a composite key? Explain with a suitable example.
Topic: Keys in the Relational Model • 3 marks marks
A composite key is a primary key that consists of two or more attributes combined together, because no single attribute alone can uniquely identify a record. Example: in an Enrolment table, neither StudentID alone nor CourseID alone is unique — a student takes many courses and a course is taken by many students — but the combination (StudentID, CourseID) is unique for every enrolment record, so together they form a composite key.
-
What is a surrogate key? Why is it used instead of a composite primary key?
Topic: Keys in the Relational Model • 3 marks marks
A surrogate key is an artificial key that is not a part of the system — it has no business meaning and is generated by the system (for example, an auto-increment number or identity column). It is used to avoid the complexity of composite primary keys: a wide multi-column key makes joins and foreign key references in other tables long, slow and error-prone, whereas a single short surrogate key keeps references simple and efficient.
-
What is an alternate key?
Topic: Keys in the Relational Model • 2 marks marks
A table may have several candidate keys. The candidate key selected as the primary key is used for unique identification, and all the remaining candidate keys are called alternate keys. For example, if both RegNo and Email are candidate keys of a Student table and RegNo is chosen as the primary key, then Email is an alternate key.
-
What is a foreign key? Which key of the other table does it refer to?
Topic: Keys in the Relational Model • 2 marks marks
A foreign key is an attribute (or set of attributes) in one table whose value refers to the primary key of another (or the same) table. It is the mechanism used to implement relationships between tables: the foreign key in the child table must either match an existing primary key value in the parent table or be NULL.
-
Differentiate between a primary key and a foreign key.
Topic: Keys in the Relational Model • 3 marks marks
1. Purpose: a primary key uniquely identifies records in its own table; a foreign key links a record to a record in another table. 2. Count: a table has only one primary key, but it can have several foreign keys. 3. NULLs and duplicates: a primary key can contain neither NULL nor duplicate values; a foreign key may contain duplicate values and, where the relationship is optional, NULL values. 4. Reference: a primary key does not refer to anything; a foreign key refers to the primary key of another table.
-
What are integrity constraints? Briefly describe entity integrity and referential integrity.
Topic: Relationships & Integrity Constraints • 5 marks marks
Integrity constraints are rules that the data in a database must satisfy so that it remains accurate and consistent; the DBMS rejects any operation that would violate them. Two important constraints are: 1. Entity integrity: the primary key of a relation cannot contain a NULL value, because a NULL primary key would make it impossible to identify that tuple uniquely. 2. Referential integrity: a foreign key value in a table must either match an existing primary key value in the referenced table or be NULL; it guarantees that relationships between tables remain valid and no 'dangling' references exist. (Domain integrity — values must lie in the allowed domain of the attribute — is another basic constraint.)
-
Which constraint is relevant for the primary key–foreign key relationship? Explain it with an example.
Topic: Relationships & Integrity Constraints • 3 marks marks
The referential integrity constraint is relevant for the primary key–foreign key relationship. It requires that every foreign key value in a child table must refer to an existing primary key value in the parent table (or be NULL). Example: the DeptID stored in an Employee row must be the ID of a department that actually exists in the Department table; the DBMS will reject inserting an employee with DeptID = 99 if there is no department 99, and it will also restrict deleting a department that still has employees.
-
In which type of database relationship can a foreign key be added in any participating table? Justify your answer.
Topic: Relationships & Integrity Constraints • 3 marks marks
In a one-to-one (1:1) relationship, the foreign key can be added in any of the participating tables. Justification: in a 1:1 relationship each record of one table is related to at most one record of the other table, so placing the key on either side still keeps the relationship unambiguous and does not create repetition. (Note: in a one-to-many relationship this freedom does not exist — the foreign key must be placed on the 'many' side only.)
-
In a one-to-many relationship, in which table is the foreign key placed, and why?
Topic: Relationships & Integrity Constraints • 3 marks marks
In a one-to-many (1:N) relationship, the foreign key is placed in the table on the 'many' side: the primary key of the 'one' side becomes a foreign key in the 'many' side table. For example, one Department has many Employees, so DeptID (the primary key of Department) is stored as a foreign key in the Employee table. Placing it the other way would force the 'one' side to hold many values in a single record, which would repeat data and break the table structure.
-
How is a many-to-many relationship implemented in a relational database? Explain with an example.
Topic: Relationships & Integrity Constraints • 5 marks marks
A many-to-many (M:N) relationship cannot be implemented directly between two tables, because a foreign key on either side would have to hold multiple values. It is implemented by creating a third table, called a junction (bridge/associative) table, which breaks the M:N relationship into two one-to-many relationships. Example: Students and Courses have an M:N relationship (a student takes many courses; a course has many students). A junction table Enrolment(StudentID, CourseID) is created, where StudentID is a foreign key to Student and CourseID is a foreign key to Course; the two columns together usually form the composite primary key of the junction table.
-
Differentiate among one-to-one, one-to-many and many-to-many relationships, giving one example of each.
Topic: Relationships & Integrity Constraints • 5 marks marks
1. One-to-one (1:1): each record in table A is related to at most one record in table B and vice versa. Example: a Person and his/her Passport. The foreign key may be placed in either table. 2. One-to-many (1:N): one record in table A is related to many records in table B, but each record in B relates to only one record in A. Example: one Department has many Employees. The foreign key is placed on the 'many' side. 3. Many-to-many (M:N): records in both tables relate to many records in the other table. Example: Students and Courses. It is implemented through a junction (bridge) table.
-
What is DDL? List any four DDL commands with their purpose.
Topic: SQL Language Categories: DDL, DML & DCL • 3 marks marks
DDL stands for Data Definition Language. It is the part of SQL used to define and modify the structure (schema) of database objects such as tables. Its main commands are: 1. CREATE — creates a new database object, e.g. CREATE TABLE. 2. ALTER — changes the structure of an existing object, e.g. adding a column. 3. DROP — deletes an object completely, along with its data. 4. TRUNCATE — removes all rows from a table while keeping its structure.
-
What is DML? List its commands and state what each one does.
Topic: SQL Language Categories: DDL, DML & DCL • 3 marks marks
DML stands for Data Manipulation Language. It is the part of SQL used to work with the data stored inside tables. Its commands are: 1. INSERT — adds new rows of data into a table. 2. UPDATE — modifies existing data in a table. 3. DELETE — removes rows from a table. 4. SELECT — retrieves (reads) data from a table; it is often grouped with DML (sometimes listed separately as DQL/DRL).
-
What is DCL? Which type of commands belong to it, and what do they do?
Topic: SQL Language Categories: DDL, DML & DCL • 3 marks marks
DCL stands for Data Control Language. It is the part of SQL that controls access to the data in the database — i.e. who is allowed to do what. It has two commands: 1. GRANT — gives a user or role permission to perform an operation (such as SELECT or INSERT) on a database object. 2. REVOKE — takes back a permission that was previously granted.
-
Differentiate between DDL, DML and DCL.
Topic: SQL Language Categories: DDL, DML & DCL • 5 marks marks
1. Full form: DDL = Data Definition Language; DML = Data Manipulation Language; DCL = Data Control Language. 2. Purpose: DDL defines the structure/schema of database objects; DML manipulates the data stored in the tables; DCL controls access permissions on the data. 3. Commands: DDL — CREATE, ALTER, DROP, TRUNCATE; DML — INSERT, UPDATE, DELETE, SELECT; DCL — GRANT, REVOKE. 4. Effect: DDL changes what objects exist and how they are structured; DML changes the rows inside the tables; DCL changes which users may perform which operations.
-
To which SQL category does the ALTER command belong? What is ALTER used for?
Topic: SQL Language Categories: DDL, DML & DCL • 2 marks marks
The ALTER command belongs to DDL (Data Definition Language). It is used to change the structure of an existing database object — for example, to add a new column to a table, drop a column, or modify a column's data type — without recreating the object.
-
Differentiate between the DELETE and TRUNCATE commands.
Topic: SQL Language Categories: DDL, DML & DCL • 3 marks marks
1. Category: DELETE is a DML command; TRUNCATE is a DDL command. 2. Selection of rows: DELETE can remove selected rows by using a WHERE clause; TRUNCATE removes all rows of the table — no WHERE clause is possible. 3. Speed and logging: DELETE removes rows one by one and is slower; TRUNCATE deallocates the data pages and is faster. 4. Rollback: a DELETE operation can be rolled back; a TRUNCATE operation generally cannot be rolled back.
-
Which SQL command is used to add data into a table? Write its general syntax.
Topic: SQL Language Categories: DDL, DML & DCL • 2 marks marks
The INSERT command (a DML command) is used to add data into SQL tables. Its general syntax is: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); Example: INSERT INTO Student (RegNo, Name) VALUES (101, 'Ali');
-
Write the SQL commands to give a user permission to SELECT and INSERT on the Student table, and then to take that permission back. To which category do these commands belong?
Topic: SQL Language Categories: DDL, DML & DCL • 3 marks marks
GRANT SELECT, INSERT ON Student TO user_name; REVOKE SELECT, INSERT ON Student FROM user_name; Both commands belong to DCL (Data Control Language), the part of SQL responsible for granting or revoking access to the data in a database.
-
Name the three main categories of SQL commands. Is 'DFL' a category of SQL?
Topic: SQL Language Categories: DDL, DML & DCL • 2 marks marks
The three main categories of SQL commands are: (1) DDL — Data Definition Language, (2) DML — Data Manipulation Language, and (3) DCL — Data Control Language. No, 'DFL' is not a category of SQL — there is no such sub-language in SQL.