DBMS Workbook
DBMS Workbook
137
3.4 Database Design and Normalization
UPDATE Statement:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
These are just a few examples of SQL commands and their syntax. SQL is a powerful language with many more
commands and features for managing relational databases.
138
3.4 Database Design and Normalization
Database Schema: The database schema defines the structure of the database, including the tables, columns,
constraints, and relationships between tables. It provides a blueprint for organizing and storing data in the
database.
Normalization: Normalization is the process of organizing data in a database to minimize redundancy and
dependency. It involves dividing large tables into smaller, more manageable tables and defining relationships
between them to ensure data integrity and optimize performance.
Indexing: Indexing is used to improve the performance of database queries by creating indexes on one or more
columns of a table. Indexes allow for faster data retrieval by enabling the database to quickly locate and access
the required data.
Data Integrity Constraints: Data integrity constraints, such as primary key, foreign key, unique key, and
check constraints, are used to enforce data integrity rules and ensure the accuracy and consistency of data in the
database.
Normalization is a critical aspect of database design that helps in reducing data redundancy, improving data
integrity, and optimizing database performance. It involves several normalization forms, each addressing specific
types of data redundancy and dependency:
1. First Normal Form (1NF): Eliminates repeating groups and ensures that each column contains atomic values.
2. Second Normal Form (2NF): Eliminates partial dependencies by ensuring that each non-key attribute is fully
functionally dependent on the primary key.
3. Third Normal Form (3NF): Eliminates transitive dependencies by ensuring that each non-key attribute is di-
rectly dependent on the primary key.
4. Boyce-Codd Normal Form (BCNF): A stricter form of 3NF that eliminates all non-trivial functional depen-
dencies.
5. Fourth Normal Form (4NF): Addresses multi-valued dependencies by splitting multi-valued attributes into
separate tables.
6. Fifth Normal Form (5NF): Addresses join dependencies by decomposing tables into smaller, independent
tables.
By following the principles of normalization, database designers can create well-structured, efficient databases
that support data integrity, scalability, and performance.
Normalization Example
Consider the following table representing information about students and their courses:
First Normal Form (1NF): The table is already in 1NF as it contains only atomic values in each cell.
Second Normal Form (2NF): To achieve 2NF, we need to ensure that every non-key attribute is fully functionally
dependent on the primary key. Here, the primary key is Student_ID and Course_ID. Since Student_Name is functionally
dependent on Student_ID and Course_Name is functionally dependent on Course_ID, the table is in 2NF.
Third Normal Form (3NF): In 3NF, we need to eliminate transitive dependencies. Here, Student_Name depends
only on Student_ID, and Course_Name depends only on Course_ID, so the table is in 3NF.
Boyce-Codd Normal Form (BCNF): BCNF is a stricter form of 3NF that eliminates all non-trivial functional
dependencies. Since there are no non-trivial functional dependencies other than the candidate keys, the table is in
139
3.5 Indexing and Query Optimization
BCNF.
140
3.7 NoSQL Databases
Concurrency Control is a key aspect of transaction management that deals with the simultaneous execution of
multiple transactions. Concurrency control techniques ensure that transactions execute correctly and do not interfere
with each other, thereby preserving data consistency and integrity.
Concurrency Control Techniques:
Locking: Lock-based concurrency control mechanisms use locks to prevent conflicting operations from access-
ing the same data simultaneously. Transactions acquire locks on data items before reading or writing them and
release the locks after completing the operation.
Multiversion Concurrency Control (MVCC): MVCC allows multiple versions of data items to exist concur-
rently in the database, enabling transactions to read a consistent snapshot of the database without being blocked
by concurrent write operations.
Timestamp Ordering: Timestamp-based concurrency control assigns a unique timestamp to each transaction
and ensures that transactions execute in a serializable order based on their timestamps. Conflicting transactions
are ordered based on their timestamps to maintain consistency.
Effective transaction management and concurrency control are essential for maintaining the integrity and relia-
bility of database systems in multi-user environments.
141
3.8 Big Data and Distributed Databases
142
3.10 Frequently Asked Interview Questions
and independently deployable services, is gaining popularity. DBMS technologies that support microservices
architectures, such as containerization, orchestration, and service discovery, are becoming increasingly impor-
tant.
Graph Databases: Graph databases are gaining traction for applications that require efficient storage and query-
ing of graph-structured data, such as social networks, recommendation systems, and network analysis. Graph
databases offer powerful graph algorithms, traversal capabilities, and schema flexibility.
Blockchain Databases: Blockchain technology is being used to implement decentralized and tamper-resistant
databases for applications such as cryptocurrency, supply chain management, and digital identity verification.
Blockchain databases provide immutability, transparency, and cryptographic security.
These trends are driving innovation in the field of DBMS and shaping the future of data management and analytics.
143
3.10 Frequently Asked Interview Questions
144
3.10 Frequently Asked Interview Questions
145
3.10 Frequently Asked Interview Questions
123. What are stored procedures and how do you create them in SQL?
124. What is indexing in SQL and why is it important?
125. How do you optimize SQL queries for performance?
126. Explain the difference between relational algebra and SQL.
127. What are the fundamental operations in relational algebra?
128. How do you represent relations in relational algebra?
129. Describe the basic syntax of relational algebra expressions.
130. What is a relational schema, and how is it used in relational algebra?
131. Explain the SELECT operation in relational algebra.
132. How does the PROJECT operation work in relational algebra?
133. Describe the difference between the JOIN and CROSS JOIN operations.
134. What is the difference between UNION and INTERSECTION in relational algebra?
135. Explain the purpose of the RENAME operation in relational algebra.
136. How do you perform set difference in relational algebra?
137. What is the DIVISION operation in relational algebra, and when is it used?
138. Describe the SEMIJOIN operation and its significance in relational algebra.
139. What is the NATURAL JOIN operation, and how does it differ from other types of joins?
140. Explain the purpose of the OUTER JOIN operation in relational algebra.
141. How do you perform aggregation operations in relational algebra?
142. Describe how recursive queries can be represented in relational algebra.
143. How can you optimize relational algebra expressions for better performance?
144. Explain the concept of query optimization in relational algebra.
145. What are some common optimization techniques used in relational algebra?
146. How does indexing impact query performance in relational algebra?
147. Describe the concept of query execution plans in relational algebra.
148. Discuss the role of relational algebra in relational database theory.
149. How does relational algebra facilitate database query processing?
150. Explain how relational algebra operations are used in practice for database manipulation.
151. Describe the relationship between relational algebra and database normalization.
152. How does relational algebra relate to the relational model of data?
153. How do you write a relational algebra expression to find the Cartesian product of two relations?
154. Explain how you would retrieve data from multiple tables using relational algebra.
155. How do you perform nested queries in relational algebra?
156. Describe the process of composing complex relational algebra expressions.
157. Provide an example of a complex query expressed in relational algebra.
158. Can you provide examples of real-world scenarios where relational algebra is used?
159. How does relational algebra support data manipulation in database management systems?
160. Describe how relational algebra expressions are translated into SQL queries in practice.
161. What are some challenges associated with using relational algebra in database systems?
162. Discuss the limitations of relational algebra in representing complex queries.
163. How do you address scalability issues when working with relational algebra expressions?
164. Explain the trade-offs involved in using relational algebra for database query processing.
165. What is a functional dependency (FD) in the context of relational databases?
166. How do you define a functional dependency between attributes in a relation?
167. Explain the difference between a candidate key and a superkey in terms of functional dependencies.
168. What is closure of attributes in functional dependencies, and why is it important?
146
3.10 Frequently Asked Interview Questions
147
3.10 Frequently Asked Interview Questions
214. What are the trade-offs between different isolation levels in terms of consistency and concurrency?
215. How does a DBMS ensure the isolation property for each isolation level?
216. Can you provide examples of scenarios where different isolation levels would be appropriate?
217. Describe the process of transaction recovery in a DBMS.
218. What is a checkpoint, and how does it help in transaction recovery?
219. Explain the role of the transaction log in recovery operations.
220. How does a DBMS handle system crashes during transaction execution?
221. Can you explain the difference between forward and backward recovery techniques?
222. What are distributed transactions, and how do they differ from local transactions?
223. Describe the challenges associated with managing distributed transactions.
224. How do you ensure atomicity and consistency in distributed transactions?
225. Explain the role of distributed locks in ensuring data integrity across multiple sites.
226. What is a two-phase commit protocol, and how does it work in distributed transactions?
227. How can you optimize transaction processing for better performance?
228. Describe the concept of transaction batching and its impact on performance.
229. What are the factors that affect transaction throughput and response time?
230. Explain the role of indexing and caching in improving transaction performance.
231. How do you measure and monitor transaction performance in a DBMS?
232. Can you provide examples of real-world scenarios where transaction management is crucial?
233. How do e-commerce platforms utilize transactions to ensure data consistency and integrity?
234. Describe how banking systems handle transactions to maintain accurate account balances.
235. What are some challenges unique to handling transactions in large-scale distributed systems?
236. How do social media platforms ensure data consistency and isolation in transactional operations?
237. What is an unstructured database, and how does it differ from structured databases?
238. Can you provide examples of unstructured data formats commonly stored in unstructured databases?
239. Explain the challenges associated with managing and querying unstructured data compared to structured data.
240. How do unstructured databases handle schema flexibility and schema evolution?
241. Describe the storage mechanism used in unstructured databases.
242. How do you efficiently retrieve and query unstructured data from an unstructured database?
243. Explain the role of indexing in unstructured databases and its impact on retrieval performance.
244. Can you discuss the trade-offs between different storage and retrieval techniques for unstructured data?
245. What are some common methods for querying unstructured databases?
246. Explain the concept of full-text search and how it is implemented in unstructured databases.
247. How do you perform advanced analytics and data mining on unstructured data?
248. Describe the challenges associated with performing complex queries on unstructured data compared to structured
data.
249. How do unstructured databases scale horizontally to handle large volumes of data?
250. What are some strategies for optimizing performance in unstructured databases?
251. Explain how distributed computing techniques are used to improve scalability and performance in unstructured
databases.
252. Can you discuss the role of caching and replication in enhancing performance in unstructured databases?
253. How do you integrate unstructured data from different sources into an unstructured database?
254. Describe the process of transforming unstructured data into a structured format for analysis.
255. What are some challenges associated with integrating and transforming unstructured data?
256. How do you ensure data security and privacy in unstructured databases?
257. What are some common security vulnerabilities associated with unstructured databases?
148
3.10 Frequently Asked Interview Questions
258. Explain the role of access control mechanisms in protecting unstructured data.
259. How do unstructured databases handle schema evolution and versioning?
260. Can you discuss the challenges of maintaining backward compatibility when evolving the schema of unstructured
data?
261. What strategies can be used to manage schema changes in unstructured databases while minimizing disruption?
262. Can you provide examples of industries or use cases where unstructured databases are commonly used?
263. How do content management systems leverage unstructured databases to store and manage documents, images,
and multimedia content?
264. Explain how social media platforms utilize unstructured databases to store and analyze user-generated content.
265. What are some challenges specific to healthcare or scientific research that can be addressed using unstructured
databases?
266. Can you discuss the role of unstructured databases in supporting natural language processing and sentiment
analysis applications?
267. What are some emerging technologies or trends that are shaping the future of unstructured databases?
268. How do advancements in machine learning and artificial intelligence impact the capabilities of unstructured
databases?
269. Can you discuss the potential impact of blockchain technology on the evolution of unstructured databases?
270. What are some key areas of research or development in unstructured databases that you find promising?
149
3.11 Worksheets
3.11 Worksheets
Worksheet 1
150
3.11 Worksheets
C. Three
D. Multiple
10. A common approach to normalization is to t helargertableintosmallertablesandlinkthemtogetherbyusingrelationships.
A. Add
B. Subtract
C. Multiply
D. Divide
Subjective Questions
1. Define SQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. List out the Numeric Data and character Data Types in MySQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. List out the commands under DML and their syntax.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
151
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
4. Based on the given table “SALE” answer the question (i) and (ii)
(i) Can we take QTY column of the above table as Primary Key? If no give reason?
(ii) Which column is best suitable for applying Primary Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. What is referential Integrity? How it is implemented in any table?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Table T1 contains 10 Rows and 4 Columns; Table T2 contains 20 Rows and 3 Columns. After performing
Cartesian product of T1 and T2, what will be the degree and cardinality of Resultant output?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
152
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
153
3.11 Worksheets
Worksheet 2
154
3.11 Worksheets
Subjective Questions
1. Write any 2 characteristics of a Relation.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What is alternate Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. From the following Tables: Table 3.2 (EMP) AND Table 3.3 (JOB) answer the questions
155
3.11 Worksheets
4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Mr. Peter created a table in MySQL. later on, he found that there should have been another column in the table.
Which command should he use to add another column to the table.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
156
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Give 1 example for aggregate functions (count, max, min, sum).
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
157
3.11 Worksheets
Worksheet 3
158
3.11 Worksheets
Subjective Questions
1. Observe the following table and answer the questions TABLE 3.5 VISITOR and answer the question (i) , (ii)
and (iii)
(i) Write the name of most appropriate columns which can be considered as Candidate keys
(ii) Out of selected candidate keys, which one will be the best to choose as Primary Key?
(iii) What is the degree and cardinality of the table
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. What is the difference between Primary Key and Candidate Key?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
159
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
3. What are the differences between DELETE and DROP commands of SQL?
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Write the SQL query to display price of products without duplicate values.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Write the SQL query to drop the table employee.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write the SQL query to count the number of product with product code is PEN.
....................................................................................................
....................................................................................................
....................................................................................................
160
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
161
3.11 Worksheets
Worksheet 4
162
3.11 Worksheets
C. Isolation
D. Durability
9: In a database, prior to and after a transaction, properties are used to ensure .......
A. Consistency
B. Redundancy
C. Latency
D. Anonymity
10: Column names of any table must be:
A. Must be numeric type
B. Must be unique
C. Must be in sorted order
D. Must not be greater than 40 characters
Subjective Questions
1. Write the SQL query to update product code to PEC for product ID 1002.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
2. Write short notes on following relational terms:
a. Tuple
b. Attribute
c. Relation
d. Domain
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
3. Write the SQL query to display the maximum, minimum, average of price and total quantity of all products.
163
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
4. Differentiate between DBMS and RDBMS. Discuss its different functions.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
5. Observe the following Table 3.6 TEACHER and Table 3.7 TASK carefully and write the names of the RDBMS
operation out of (i) EQUI JOIN(ii) NATURAL JOIN(iii) SELECTION (iv)CARTESIAN PRODUCT, which
has been used to product the output as shown below. Also find the Degree and Cardinality of final RESULT.
164
3.11 Worksheets
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
6. Write the SQL queries:
(a). Retrieve all tasks along with the respective teacher information.
(b). Find out the completion date and subject for each task.
(c). Get the teacher name, subject, and task name for tasks completed on 31-05-2020.
(d). List all tasks along with the teacher’s subject and the completion date.
(e). Find out the tasks completed by each teacher with their respective subjects.
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
165