Introduction To Databases CT042-3-1-IDB
Introduction To Databases CT042-3-1-IDB
Introduction To Databases CT042-3-1-IDB
INTRODUCTION TO DATABASES.....................................................................................2
Chapter 1...............................................................................................................................2
Chapter 2...............................................................................................................................2
Chapter 3...............................................................................................................................2
Chapter 4...............................................................................................................................3
Chapter 5...............................................................................................................................3
Chapter 6...............................................................................................................................3
Chapter 7...............................................................................................................................3
Chapter 8...............................................................................................................................3
Chapter 9...............................................................................................................................4
Chapter 10.............................................................................................................................4
Chapter 11.............................................................................................................................4
Chapter 12.............................................................................................................................4
ANSWERS................................................................................................................................5
Chapter 1...............................................................................................................................5
Chapter 2...............................................................................................................................7
Chapter 3...............................................................................................................................9
Chapter 4.............................................................................................................................10
Chapter 5.............................................................................................................................11
Chapter 6.............................................................................................................................12
Chapter 7.............................................................................................................................13
Chapter 8.............................................................................................................................14
Chapter 9.............................................................................................................................15
Chapter 10...........................................................................................................................16
Chapter 11...........................................................................................................................17
Chapter 12...........................................................................................................................20
INTRODUCTION TO DATABASES
Chapter 1
1. What is data?
2. What is information?
3. What is Database?
4. What is a DBMS?
5. What are the Roles/Functions of DBMS?
6. What are the Advantages of DBMS?
7. What are the types of databases?
8. What are the types of databases based on location?
9. What are the types of databases based on its use?
10. What is the difference between data and information?
11. Describe the difference between database and DBMS?
Chapter 2
Chapter 3
1. What is a Table/Relation?
2. Define Primary Key, Secondary Key, Foreign Key, Candidate key and Composite Key
3. What is referential integrity?
4. What is entity integrity?
5. What are the conditions for selecting a primary key?
6. What is a data dictionary?
7. What is a System Catalogue?
8. What is attribute domain?
9. Why is NULL not favourable when inserting data values?
Chapter 5
Chapter 6
Chapter 7
Chapter 8
1. What is Normalization?
2. Explain the stages of Normalization.
3. Why do we need Normalization?
4. How to convert to First Normal Form (1NF)?
5. How to convert to Second Normal Form (2NF)?
6. How to convert to Third Normal Form (3NF)?
7. What is partial dependency?
8. What is transitive dependency?
Chapter 9
Chapter 10
Chapter 11
Chapter 12
1. What is Data?
Data refers to raw, unprocessed facts and figures that are collected from various sources. Data
alone does not have meaning and requires processing to be useful.
2. What is Information?
Information is processed, organized, or structured data that has been given context and
meaning. Information is useful and provides insights for decision-making.
3. What is a Database?
A Database is an organized collection of data that is stored and accessed electronically.
Databases are designed to manage large amounts of data efficiently and allow for data
retrieval, insertion, updating, and deletion. It consists of tables, rows, and columns.
4. What is a DBMS?
A Database Management System (DBMS) is software that provides an interface between the
user and the database. It allows users to create, retrieve, update, and manage data in a
database efficiently. Provides tools for data definition, data manipulation, and data control.
Example: MySQL, Oracle, SQL Server.
Data Definition: Defines data structures, such as tables and indexes. Example:
Creating a new table.
Data Storage, Retrieval, and Update: Stores data, retrieves data as per user queries,
and updates existing data. Example: Inserting new records, updating existing records.
User Access Management: Manages user permissions and access levels to ensure
data security. Example: Granting or revoking user access.
Data Integrity Management: Enforces data integrity constraints to ensure data
accuracy and consistency. Example: Primary keys, foreign keys.
Transaction Management: Ensures that database transactions are processed reliably
and adhere to ACID properties. Example: Handling multiple transactions.
Backup and Recovery: Provides mechanisms for data backup and recovery to
protect against data loss. Example: Automated backup schedules.
Data Security: Protects data from unauthorized access and breaches. Example: Data
encryption.
6. What are the Advantages of DBMS?
Advantages of DBMS include:
Data Integrity and Accuracy: Ensures data accuracy and consistency through
integrity constraints. Example: Primary and foreign key constraints.
Data Security: Implements security features to protect data. Example: User
authentication and access control.
Efficient Data Management: Provides efficient storage and retrieval of data.
Example: Indexing for fast search.
Concurrent Access: Allows multiple users to access data simultaneously. Example:
Locking mechanisms.
Data Redundancy and Inconsistency Reduction: Minimizes data duplication.
Example: Normalization.
Data Independence: Separates data from application programs. Example: Schema
changes without affecting applications.
Backup and Recovery: Robust mechanisms for data backup and recovery. Example:
Automated backups.
7. What are the types of databases?
Database can be classified into two main types: single user and multi-user.
Single User Database: Databases that supports only one user at a time. Single
User Database can be further classified into a type called Desktop User
Database. Which is a single user database running on a user’s personal computer.
Multiuser Database: Multiuser Database are the types of Databases that can
support multiple users at the same time. It can be further classified into two
groups:
o Workgroup Database: It is a multi-user database that supports a small
group of users or a single department.
o Enterprise Database: It is a multi-user database that supports a large
group of users or an entire organization.
8. What are the types of databases based on location?
There are two types of databases based on location.
Data Information
Raw and unprocessed information Processed data that holds a meaning
Not meaningful or organised Meaningful and organised
Example: 101, John Doe, 5000. Example: Employee ID 101 is John Doe,
and his salary is $5000.
11. Describe the difference between database and DBMS?
Database DBMS
A structured collection of data A software that manages databases
Stores data in tables, rows, and columns. Provides tools for creating, retrieving,
updating, and managing data.
Example: Customer database containing Example: MySQL, Oracle, SQL Server.
customer information.
Chapter 2
5. What is a Field?
A field is a basic unit of data entry in a database or file system. It represents a specific
attribute or characteristic of an entity. Fields are the columns in a table within a database.
6. What is a Record?
A record is a collection of related fields that represent a single entity or item in a database.
Records are the rows in a table within a database.
7. What are the Shortcomings of File System Data Management?
Insertion Anomaly: Occurs when certain attributes cannot be inserted into the
database without the presence of other attributes. Example: Inserting a new employee
without a department because the department information is not yet available.
Update Anomaly: Occurs when changes to data in one place are not correctly
propagated to other instances of that data. Example: Changing a customer's address
in one table but not updating it in another table where the same address is stored.
Deletion Anomaly: Occurs when the deletion of data inadvertently causes loss of
additional data that should be retained. Example: Deleting a customer record also
deletes associated order history if stored in the same table.
Chapter 3
Chapter 4
1. What is a Table/Relation?
A Table (or Relation) in a relational database is a structured format for organizing and storing
data. It consists of rows and columns, where each row represents a unique record, and each
column represents a specific attribute of the record.
2. Define Primary Key, Secondary Key, Foreign Key, Candidate key and Composite Key
Primary Key: A unique not null attribute that identifies/represents an entity in a relation.
Secondary key: Secondary Key is an attribute to make the data retrieval process faster, and it
is not necessarily unique or involved in table relationships.
Foreign Key: Foreign Key is a primary key that connects two tables in a database. That
means when a primary key from one table is used in another table to connect the tables, it
becomes a foreign key in that table.
A foreign key is an attribute in one table that links to the primary key in another table. It
establishes a relationship between the two tables.
Candidate key: Candidate key is a potential primary key. Which means any attribute that can
uniquely identify an entity can be called a candidate key and each candidate key qualifies to
be a primary key.
Composite Key: When two or more attributes work together to uniquely identify a record in
a table, then it is called a composite key. It is a primary key composed of more than one
attribute.
3. What is referential integrity?
Referential Integrity is a property of a database that ensures that relationships between tables
remain consistent. It ensures that a foreign key in one table must either be null or match a
primary key in the related table.
Example: In a database with Orders and Customers tables, referential integrity ensures that
every CustomerID in the Orders table must match a valid CustomerID in the Customers table
or be null if allowed.
4. What is entity integrity?
Entity Integrity is a constraint that ensures each table has a primary key, and that the primary
key is unique and not null. This ensures that each record in the table is uniquely identifiable.
5. What are the conditions for selecting a primary key?
Not null, unique, has a simple attribute domain, immutable and stable.
6. What is a data dictionary?
A data dictionary is a repository that contains the metadata about the data stored in a
database.
7. What is a System Catalogue?
A system catalogue is a repository very similar to a data dictionary, which is an organised and
structured collection of metadata about the data stored in a database.
Data Integrity Issues: NULL values can indicate missing or unknown data, leading
to incomplete information. Example: If a PhoneNumber column contains NULL
values, it is unclear whether the phone number is missing or simply unknown.
Query Complications: Queries involving NULL values can be complex and may
require additional handling using IS NULL or IS NOT NULL conditions. Example:
Finding records where the Salary is not null requires a specific condition.
Aggregations and Calculations: NULL values can affect aggregate functions and
calculations, leading to inaccurate results. Example: Calculating the average salary in
a table with NULL values requires excluding NULLs to get an accurate average.
Indexing and Performance: NULL values can complicate indexing and may impact
query performance. Example: Indexes may need to handle NULL values separately,
affecting search efficiency.
Consistency: Having NULL values can lead to inconsistencies in data interpretation.
Example: A NULL Email address could mean the email is not provided, not
applicable, or unknown, leading to ambiguity.
Chapter 5
Chapter 6
Advantages:
o Storage Efficiency: Reduces storage requirements by not storing redundant
data. Example: Not storing Age separately reduces space as it can be
calculated from DateOfBirth.
o Data Consistency: Ensures consistency since derived attributes are always
calculated from the most current values of other attributes. Example:
TotalPrice always reflects the latest Quantity and UnitPrice.
o Data Integrity: Minimizes the risk of discrepancies between stored values
and calculated values. Example: Calculated Age will always be accurate if
DateOfBirth is correct.
Disadvantages:
o Performance Overhead: Computation of derived attributes can add
overhead, especially if the calculations are complex or need to be performed
frequently. Example: Recalculating TotalPrice every time it is accessed.
o Complex Queries: Queries may become more complex and slower if many
derived attributes need to be computed on the fly. Example: Complex
calculations involving multiple tables.
o Limited Flexibility: Changes in the underlying attributes or their relationships
may require changes in the derivation logic. Example: If the method of
calculating TotalPrice changes, all queries using this attribute must be updated.
4. What is cardinality?
A cardinality represents the minimum and maximum number of instances of one entity that
can or must be associated with each instance of another entity. For example: 1:1, 1:M, M:M
5. What are weak entities?
A Weak Entity is an entity that cannot be uniquely identified by its own attributes alone. It
depends on a "strong" or "owner" entity to ensure its uniqueness.
Chapter 7
Chapter 8
1. What is Normalization?
Normalization is a systematic approach to organizing data in a database to reduce redundancy
and improve data integrity. The process involves dividing a database into two or more tables
and defining relationships between them to eliminate redundant data and ensure data
dependencies make sense.
2. Explain the stages of Normalization.
There are three stages of Normalization.
First Normal Form (1NF): Ensures that the table is in a tabular format, with each
column containing atomic (indivisible) values and each column containing values of a
single type.
Second Normal Form (2NF): Achieved when a table is in 1NF, and all non-key
attributes are fully functionally dependent on the primary key.
Third Normal Form (3NF): Achieved when a table is in 2NF and all the attributes
are functionally dependent only on the primary key, eliminating transitive
dependencies.
3. Why do we need Normalization?
Minimize Redundancy: Reduces duplicate data, saving storage space and preventing
inconsistencies.
Ensure Data Integrity: Ensures that data dependencies are logical and consistent,
preventing anomalies during data operations.
Simplify Maintenance: Makes the database easier to maintain and update, as changes
to data are made in one place.
Improve Performance: Improves query performance by reducing the amount of
redundant data that needs to be processed.
4. How to convert to First Normal Form (1NF)?
Eliminate Repeating Groups: Ensure that each column contains only atomic values.
Ensure Single-Valued Attributes: Each column should contain values of a single
type.
Identify a Primary Key: Choose a primary key that uniquely identifies each record.
DDL DML
Defines the data Manipulates the data
Manages database structures Used for managing data within database
structures
Includes commands like CREATE, ALTER, Includes commands like SELECT, INSERT,
DROP, TRUNCATE, and RENAME. UPDATE, and DELETE.
Chapter 10
Inner Join: Returns only the rows that have matching values in both tables.
Left Join: Returns the rows from the left table that matches the value of the right
table.
Right Join: Returns the value from the right table that matches the value from the left
table.
Full Join: Returns all the matching values from both tables.
Cartesian Join: Returns the cartesian product of both tables.
Self-Join: Joins a table to itself. Used to compare rows within the same table.
Inner Join: Returns only the rows that have matching values in both tables.
Left Join: Returns the rows from the left table that matches the value of the right
table.
Right Join: Returns the value from the right table that matches the value from the left
table.
Full Join: Returns all the matching values from both tables.
Cartesian Join: Returns the cartesian product of both tables.
Self-Join: Joins a table to itself. Used to compare rows within the same table.
Chapter 11
External Level (External Model): This is the highest level of abstraction and
represents the end users' view of the data environment.
Purpose: It provides a customized view of the database tailored to the needs of
different user groups. Each external view is a subset of the overall database, showing
only the relevant data for that user or application.
Advantages: Simplifies user interaction with the database by hiding the complexity of
the underlying data structure. Ensures data security by restricting access to certain
data based on user roles. Facilitates application development by providing specific
data views.
Conceptual Level (Conceptual Model): This level provides a global view of the
entire database as perceived by the organization. It represents the logical structure of
the database, including the relationships between data entities.
Purpose: It serves as a bridge between the external and internal levels of abstraction.
The conceptual model defines what data is stored in the database and how the data is
related.
Characteristics: Independent of the database management system (DBMS) and
hardware platform. Focuses on high-level data structures and relationships, without
detailing the actual storage mechanisms. Mostly represented using the Entity-
Relationship (ER) model.
Internal Level (Internal Model): This level provides a view of the database as seen
by the DBMS. It describes how data is stored and managed within the database
system.
Purpose: It maps the conceptual model to the physical storage structures used by the
DBMS. The internal model defines the internal schema, which includes detailed
information about data storage, indexing, and access paths.
Characteristics: Dependent on the specific DBMS being used. Includes detailed
definitions of tables, indexes, and other database objects. Manages data integrity,
security, and performance optimization.
Physical Level (Physical Model): This is the lowest level of abstraction, describing
how data is physically stored on storage media, such as disks or tapes.
Purpose: It deals with the actual implementation of the database, including file
structures, data compression, and data encryption.
Characteristics: Highly dependent on the hardware and software used to implement
the database. Requires a detailed understanding of the physical storage mechanisms
and performance considerations.
2. What is EERD?
The Extended Entity Relationship (EER) Model is an enhancement of the traditional Entity
Relationship (ER) model. It introduces additional semantic constructs to provide more
detailed modeling of data and their relationships. These enhancements help to better capture
the complexities of real-world scenarios.
3. Explain Entity Supertypes and Subtypes.
Entity Supertype: A generic entity type that is related to one or more subtypes. It
contains attributes that are common to all its subtypes.
Entity Subtype: A more specific entity type that contains attributes unique to that
subtype.
Example: In a university database, Person could be an entity supertype with subtypes
Student, Professor, and Staff. Common attributes like Name and Address would be in
Person, while Major might be unique to Student.
4. Explain the Key Concepts in the EER Model.
Entity Supertypes and Subtypes:
Entity Supertype: A generic entity type that is related to one or more subtypes. It
contains attributes that are common to all its subtypes.
Entity Subtype: A more specific entity type that contains attributes unique to that
subtype.
Example: In a university database, Person could be an entity supertype with subtypes
Student, Professor, and Staff. Common attributes like Name and Address would be in
Person, while Major might be unique to Student.
Specialization Hierarchy:
Definition: This hierarchy depicts the arrangement of higher-level supertypes and
lower-level subtypes.
IS-A Relationships: Relationships between supertypes and subtypes are often
described using "IS-A" terminology. For example, a Student IS-A Person.
Levels: Can have multiple levels, where a subtype itself can act as a supertype for
other subtypes.
Attribute Inheritance: Subtypes inherit attributes and relationships from their
supertype.
Inheritance:
Definition: This mechanism allows a subtype to inherit attributes and relationships
from its supertype.
Primary Key Inheritance: All subtypes inherit the primary key attribute from their
supertype, ensuring unique identification across the hierarchy.
Subtype Discriminator:
Definition: An attribute in the supertype that determines to which subtype a particular
instance belongs.
Example: A Person entity might have a Role attribute that indicates whether the
person is a Student, Professor, or Staff.
Disjoint and Overlapping Constraints:
Disjoint Subtypes: Subtypes that contain unique subset of supertype entity set
Example: A person cannot be both a Student and a Professor at the same time.
Overlapping Subtypes: Subtypes that contain nonunique subsets of supertype entity
set.
Example: A person can be both an Alumni and a Donor.
Completeness Constraint:
• Definition: Specifies whether an instance of a supertype must also be a member of at
least one subtype. Specifies whether each entity supertype occurrence must also be
member of at least one subtype.
Partial Completeness: Some instances of the supertype may not belong to any
subtype.
Example: Not all Persons in the university database need to be either Student,
Professor, or Staff.
Total Completeness: Every instance of the supertype must be a member of at least one
subtype.
Example: Every Vehicle must be either a Car, Truck, or Motorcycle.
Specialization and Generalization:
Specialization: A top-down approach where a higher-level entity (supertype) is
divided into lower-level entities (subtypes) based on unique characteristics.
Example: From Employee to Engineer and Manager.
Generalization: A bottom-up approach where lower-level entities (subtypes) are
combined to form a higher-level entity (supertype) based on shared characteristics.
Example: From Savings Account and Checking Account to Account.
Chapter 12
People
Hardware
Software
Database(s)
Application Programs
Procedures
2. What is SDLC?
The SDLC traces the history (life cycle) of an information system. It provides the "big
picture" within which database design and application development can be mapped out and
evaluated. The SDLC is divided into five phases:
Planning
Analysis
Detailed Systems Design
Implementation
Maintenance
This process is iterative rather than sequential, meaning that it may go through multiple
cycles before the final system is delivered.
3. What are the phases of SDLC? Explain
Planning: Provides a general overview of the company and its objectives. Initial assessment
of information flow and requirements. Evaluation of alternative solutions, including technical
aspects of hardware and software requirements and system costs.
Analysis: Detailed examination of problems defined during the planning phase. Thorough
audit of user requirements and existing systems. Creation of logical system designs using
tools such as Data Flow Diagrams (DFDs), Hierarchical Input Process Output (HIPO)
diagrams, and Entity Relationship (ER) diagrams. Functional descriptions of system
components.
Detailed Systems Design: Completion of system process designs. Includes technical
specifications and steps for system conversion. Plans for training principles and
methodologies.
Implementation: Installation of hardware, DBMS software, and application programs. Cycle
of coding, testing, and debugging continues until the system is ready for delivery. Creation
and customization of the database, including tables, views, and user authorizations.
Maintenance: Grouped into corrective maintenance (response to errors), adaptive
maintenance (due to changes in the business environment), and perfective maintenance
(system enhancements). Utilizes Computer-Assisted Systems Engineering (CASE) tools for
efficiency.
4. What is DBLC?
The DBLC describes the history of the database within the information system. It involves
several phases, starting from initial study to maintenance.
5. What are the phases of DBLC? Explain
1. Database Initial Study: Understand the organization’s requirements and define the scope
of the database project.
Analyze company situation.
Define problems and constraints.
Define objectives.
Define scope and boundaries.