0% found this document useful (0 votes)
7 views21 pages

Database notes

A database is an organized collection of data that facilitates efficient storage and retrieval. Its evolution includes hierarchical databases in the 1960s, the introduction of the Relational Database Model in the 1970s, and the emergence of NoSQL databases in the 2000s. Key concepts discussed include database architecture, data independence, and the roles of different types of users.

Uploaded by

Ibrahim Arshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

Database notes

A database is an organized collection of data that facilitates efficient storage and retrieval. Its evolution includes hierarchical databases in the 1960s, the introduction of the Relational Database Model in the 1970s, and the emergence of NoSQL databases in the 2000s. Key concepts discussed include database architecture, data independence, and the roles of different types of users.

Uploaded by

Ibrahim Arshid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Database: Definition and Overview

A database is an organized collection of data that allows efficient storage, retrieval, and
management of information. It is designed to store data systematically so that users can
access, manipulate, and update it easily.

History of Database

The concept of databases evolved over time:

1. 1960s – The first databases were hierarchical and network databases (e.g., IBM’s
IMS).
2. 1970s – The Relational Database Model (RDBMS) was introduced by E.F. Codd,
leading to SQL-based databases.
3. 1980s–1990s – Advanced database technologies like Object-Oriented Databases
(OODBMS) and Data Warehousing emerged.
4. 2000s–Present – The rise of NoSQL databases, cloud databases, and Big Data
solutions.

Advantages and Disadvantages of Databases

Advantages:

1. Efficient Data Management – Organizes data systematically.


2. Data Security – Protects data with authentication and authorization.
3. Minimized Data Redundancy – Avoids data duplication through normalization.
4. Data Integrity and Consistency – Ensures accurate and consistent data.
5. Easy Data Retrieval – Allows fast access using queries (SQL).
6. Multi-User Access – Supports concurrent users.

Disadvantages:

1. High Cost – Expensive to develop and maintain.


2. Complexity – Requires skilled personnel to manage.
3. Performance Issues – Can slow down with large data sets.
4. Security Risks – Vulnerable to cyber-attacks if not properly secured.
5. Data Loss Risk – Hardware or software failure may lead to data loss.

Levels of Data

1. Real-world Data – Raw data collected from real-world scenarios (e.g., customer
records, sales data).
2. Metadata – Data that describes other data (e.g., schema, data types, relationships).
3. Data Occurrence – Actual instances of data stored in the database.

Database Users

1. Application Programmers

 Develop applications that interact with the database using programming languages
like Java, Python, or SQL.

2. End Users

 Naïve Users – Use applications without knowing database operations (e.g., bank
customers using an ATM).
 Sophisticated Users – Write complex queries and reports (e.g., data analysts,
database administrators).

1. Define Database Architecture.

Answer:

Database Architecture refers to the design and structure of a database system, including
how data is stored, processed, and accessed. It ensures efficient data management and
supports multiple user views while maintaining data integrity and security.

2. What is Data Independence? Explain its importance.

Answer:

Data Independence refers to the ability to change the database schema without affecting
the application programs or user interfaces.

Types of Data Independence:

1. Logical Data Independence – Ability to modify the conceptual schema without


affecting external applications.
2. Physical Data Independence – Ability to modify the internal schema (storage
structure) without changing the conceptual schema.

Importance of Data Independence:

 Allows flexibility in modifying the database.


 Reduces maintenance costs.
 Ensures long-term usability of applications.

3. Explain the Three-Level Architecture of DBMS with a diagram.

Answer:

The Three-Level Architecture, also called the ANSI/SPARC Architecture, is designed to


separate the user’s view from physical storage.

Levels of DBMS Architecture:

1.

External Level (User View)

2.

o Defines how individual users view the data.


o Multiple users can have different views of the same data.
o Example: One user sees full date of birth, another sees only the age.

3.

Conceptual Level (Logical View)

4.

o Represents the entire database structure as seen by the DBA (Database


Administrator).
o Defines entities, attributes, and relationships.
o Independent of storage and application programs.

5.

Internal Level (Physical View)

6.

o Defines how data is stored on physical storage.


o Optimized for performance, indexing, and security.

Diagram:

pgsql
CopyEdit
| External View 1 | External View 2 | External View n |
|----------------|----------------|----------------|
| Conceptual Schema (Logical Level) |
| Internal Schema (Physical Level) |
| Database Storage (Disk, Files, etc.) |

4. What are the objectives of the Three-Level Architecture?

Answer:

 To separate the user’s view from the physical representation of data.


 To allow multiple views of the same data.
 To provide a consolidated and flexible representation of data.
 To enable data independence and easy modification at different levels.

5. What is the External View in DBMS? Give examples.

Answer:

The External View is the way users perceive the database, limiting access to only relevant
data.

Characteristics:

 User-specific – Different users see different views.


 Security & Simplicity – Users only see what they need.
 Virtual/Calculated Data – Example: Age can be calculated from Date of Birth.

Examples:

 A bank customer sees only their account balance, while the bank manager sees all
customer accounts.
 A hospital receptionist sees patient names and appointment times, but the doctor
sees full medical records.

6. What is the Conceptual View? What information does it contain?

Answer:

The Conceptual View (Logical Level) is the entire database representation, defining the
structure, relationships, and constraints.

Contains:
 All Entities and Attributes (e.g., Employee, Department).
 Relationships between entities.
 Constraints (e.g., Employee ID must be unique).
 Security and integrity information.

Example:

Name DoB Dept Dept ID


Rana Aslam 12/09/70 Sales D001
Marya Wasti 29/02/80 HR D005

7. Explain the Internal Level in DBMS Architecture.

Answer:

The Internal Level (Physical Level) deals with how data is physically stored on the system.

Characteristics:

 Describes storage methods (e.g., indexing, hashing).


 Optimized for performance.
 Deals with file organization (e.g., B-Trees for indexing).

Example:

 The way tables are stored in memory using file structures.


 How indexes improve search speed.

8. Who are the different types of Database Users?

Answer:

There are two main categories of database users:

1.

Application Programmers:

2.

o Write programs that interact with the database.


o Use languages like SQL, Python, Java to access data.

3.
End Users:

4.

o Naïve Users – Use applications without technical knowledge (e.g., ATM users).
o Sophisticated Users – Use complex queries and reports (e.g., Data Analysts,
DBAs).

Conclusion (Exam Tip)

 Focus on Three-Level Architecture, its importance, and how it provides data


independence.
 Understand the different views (External, Conceptual, Internal) with examples.
 Be clear on database users and their roles.
 Diagrams help in better explanation and scoring high in exams.

Lecture 3: Database Architecture and Data Independence

Short Questions (2-5 marks)

1.

What is the purpose of the three-level database architecture?


The three-level architecture separates user views from the physical structure of the
database, allowing flexibility, security, and efficient data management.

2.
3.

Name the three levels of database architecture and briefly describe each.

4.
1. External Level: Represents how users interact with the database through
different views.
2. Conceptual Level: Represents the overall logical structure, including entities,
attributes, and relationships.
3. Internal Level: Handles physical storage, indexing, and data organization.
5.

Why is it necessary to separate the external view from the conceptual view?
Users have different perspectives on data, and separating the external view allows
customization without affecting the database’s logical structure.
6.
7.

Give an example of virtual or calculated data in an external view.


Age is an example of virtual data; it is calculated from the date of birth rather than
being stored directly in the database.

8.
9.

What is the role of DBMS in handling external views?


The DBMS creates different external views based on user needs, providing a user-
friendly interface while ensuring security and controlled access to data.

10.

Long Questions (10-20 marks)

1.

Explain the three-level architecture of DBMS with the help of a diagram.


Answer should include:

2.

1. A well-labeled diagram showing External, Conceptual, and Internal levels.


2. Explanation of how each level functions.
3. The importance of mappings (External/Conceptual and Conceptual/Internal).
4. Example scenarios where this architecture is beneficial (e.g., a banking system
where customers, accountants, and managers see different views).

3.

Describe the conceptual schema. What does it contain? Why is it important?


Answer should cover:

4.

1. The conceptual schema contains entity types, relationships, attributes,


constraints, and security rules.
2. It serves as the overall logical representation of data.
3. It provides a stable structure despite changes in the physical or external layers.
4. Example: How a university database conceptual schema stores student,
faculty, and course details.
Lecture 4: Data Independence and DBMS Functions

Short Questions (2-5 marks)

1.

What is data independence? Why is it important?


Data independence allows changes at lower levels (physical or conceptual) without
affecting upper levels, ensuring system flexibility and reducing maintenance costs.

2.
3.

Differentiate between logical and physical data independence.

4.

1. Logical Data Independence: Changes in the conceptual schema do not affect


external views.
2. Physical Data Independence: Changes in the internal schema do not affect the
conceptual schema.

5.

Give an example of logical data independence.


Adding a new column (e.g., “Nationality” in the student table) does not affect user
views or application programs.

6.
7.

What are the main functions of a DBMS?


Data processing, user-accessible catalog, transaction support, concurrency control,
recovery services, authorization, data communication support, and integrity services.

8.
9.

What are the different types of DBMS environments?

10.

 Single-user: One user at a time.


 Multi-user: Many users access the database simultaneously.
 Teleprocessing: A central server handles requests from multiple terminals.
 File Server: A LAN-based system where a file server provides access to multiple users.
 Client-Server: Database operations are handled by a dedicated server while clients
send requests.

Long Questions (10-20 marks)

1. Explain data independence in detail. Why is it a major advantage of DBMS?


Answer should cover:

 Definition and importance of data independence.


 Types: Logical and Physical.
 Example scenarios where data independence is useful (e.g., modifying an index
structure without affecting application programs).
 The role of schema mappings in achieving independence.
 A comparison of traditional file-based systems vs. DBMS in terms of flexibility and
maintenance.

1. Discuss the functions of a DBMS with examples.


Answer should include:

 Detailed explanation of key functions such as data processing, transaction


management, concurrency control, security, and integrity enforcement.
 Real-world examples (e.g., ATM transactions for concurrency control, airline booking
systems for transaction support).
 How DBMS ensures smooth multi-user access and data consistency.

Short Questions (2-5 Marks)

1.

What is the purpose of the Entity-Relationship (E-R) data model?


The E-R data model is a semantic data model used for the graphical representation of
conceptual database design.

2.
3.

List the major components of the E-R model.

4.
1. Entities
2. Attributes
3. Relationships
5.

Define an entity in the context of the E-R model.


An entity is a distinct object or thing in a database that has properties (attributes). It
can be a person, place, event, or concept.

6.
7.

Differentiate between Entity Type, Entity Instance, and Entity Set.

8.

1. Entity Type: A label assigned to a group of similar objects (e.g., Employee).


2. Entity Instance: A specific occurrence of an entity type (e.g., an employee
named M. Sharif).
3. Entity Set: The collection of all entity instances of an entity type (e.g., all
employees in an organization).

9.

What is a weak entity type? Provide an example.


A weak entity type is an entity that cannot exist independently and relies on a strong
entity. Example: "Dependents" entity in an Employee-Dependent relationship.

10.
11.

What is the difference between a strong and weak entity type?

12.

1. Strong Entity Type: Can exist independently, has its own primary key.
2. Weak Entity Type: Cannot exist without a related strong entity and uses a
foreign key (or a combination of attributes) for identification.

13.

What are the naming conventions for entity types?

14.

1. Use singular nouns.


2. Use organization-specific names.
3. Write in capital letters.
4. Use consistent abbreviations if needed.
15.

What is an attribute in an E-R model?


An attribute is a defining property or characteristic of an entity type (e.g., Student
Name, Employee ID).

16.
17.

Define the domain of an attribute.


The domain of an attribute is the set of all possible values that an attribute can take
(e.g., the "Gender" attribute may have values {Male, Female, Other}).

18.
19.

List the types of attributes in the E-R model.

20.

 Single vs. Composite Attributes


 Single-valued vs. Multi-valued Attributes
 Stored vs. Derived Attributes

Long Questions (10-20 Marks)

1. Explain the concept of weak and strong entity types with examples.
Answer should include:

 Definitions of weak and strong entity types.


 Characteristics of each type.
 An example of each (e.g., Employee (strong) and Dependents (weak)).
 A well-labeled E-R diagram showing relationships.

1. Describe different types of attributes in the E-R model with examples.


Answer should cover:

 Simple vs. Composite Attributes (e.g., Name vs. Full Name with First and Last).
 Single-valued vs. Multi-valued Attributes (e.g., Age vs. Phone Numbers).
 Stored vs. Derived Attributes (e.g., Date of Birth vs. Age).
 Diagram representing these attributes in an entity.

1. Draw an E-R diagram for an Employee database including attributes and


relationships.
Answer should include:
 Entity: Employee (Attributes: empId, Name, Address, DateHired).
 Weak Entity: Dependents (Attributes: Name, Age, Relationship).
 Relationship: "Has Dependents" between Employee and Dependents.
 Attribute symbols (ovals), entities (rectangles), and relationships (diamonds).

1. Explain the role of attributes in entity definition and classification.


Answer should include:

 How attributes define entity characteristics.


 The importance of domains.
 Classification into different types.
 Examples of attributes from real-world applications (e.g., student database, hospital
management system).

Short Questions (2-5 Marks)

1.

What is a key in the context of a database?


A key is an attribute or a set of attributes used to uniquely identify an entity instance
in a database.

2.
3.

List different types of keys in a database.

4.
1. Super Key
2. Candidate Key
3. Primary Key
4. Secondary Key
5. Alternate Key
5.

Differentiate between a simple key and a composite key.

6.

1. Simple Key: A key that consists of a single attribute (e.g., Student ID).
2. Composite Key: A key that consists of multiple attributes (e.g., {Program Code,
Course Code}).

7.
What is a super key? Provide an example.
A super key is any set of attributes that uniquely identifies an entity. Example:
{StudID, Name} for a Student entity.

8.
9.

Explain the concept of a candidate key.


A candidate key is a minimal super key, meaning it uniquely identifies an entity
without containing any extra attributes.

10.
11.

How is a primary key different from a candidate key?

12.

1. Primary Key: The chosen candidate key used for entity identification.
2. Candidate Key: A potential key that can uniquely identify an entity but may not
be selected as the primary key.

13.

What are alternate keys?


Alternate keys are candidate keys that are not chosen as the primary key but can still
uniquely identify records.

14.
15.

What is the purpose of a secondary key?


A secondary key is used for searching and accessing data based on non-unique
attributes (e.g., Student Name in a database where Student ID is the primary key).

16.
17.

Can a primary key contain NULL values? Why or why not?


No, a primary key cannot contain NULL values because it is used to uniquely identify
records in a table.

18.
19.
Give an example of a composite key.
Example: In a university database, {StudentID, CourseID} can be a composite key for
the Enrollment entity.

20.

Long Questions (10-20 Marks)

1.

Explain the different types of keys in a relational database with examples.


Answer should include:

2.

1. Super Key (Definition & Example)


2. Candidate Key (Definition & Example)
3. Primary Key (Definition & Example)
4. Alternate Key (Definition & Example)
5. Secondary Key (Definition & Example)

3.

Differentiate between Super Key, Candidate Key, and Primary Key with examples.
Answer should cover:

4.

1. Definitions of each type of key.


2. Examples (using a table with sample data).
3. Explanation of how they are related but different.

5.

Draw an E-R diagram showing different key attributes for a Student database.
Answer should include:

6.

1. Entities: Student, Course, Enrollment


2. Attributes for Student: {StudentID (Primary Key), Name, Address, Program}
3. Composite Key for Enrollment: {StudentID, CourseID}

7.
Why are keys important in a relational database? Explain with examples.
Answer should include:

8.

1. Importance of unique identification of records.


2. Prevention of duplicate data.
3. Relationship establishment between tables.
4. Example of a well-structured database using keys.

Keys in Database Management System (DBMS)

Keys are essential in relational databases to uniquely identify records in a table. Below are
the different types of keys with explanations and examples.

1. Super Key

A super key is any set of attributes that uniquely identifies an entity in a table. It may
contain additional attributes that are not necessary for uniqueness.

Example

Consider a Student table:

StudentID Name Address Phone Email


S101 Ali Khan Lahore 03123456789 [email protected]
S102 Sara Malik Islamabad 03219876543 [email protected]
S103 Bilal Ahmed Karachi 03001112233 [email protected]

 Possible Super Keys:


o {StudentID}
o {StudentID, Name}
o {StudentID, Phone}
o {StudentID, Email}
o {StudentID, Name, Phone, Email} (Contains extra attributes)

Note: Every super key contains at least one attribute that uniquely identifies records.

2. Candidate Key

A candidate key is a minimal super key, meaning it uniquely identifies a record but does
not contain extra attributes.

Example (From Student Table)


 Possible Candidate Keys:
o {StudentID} (Minimal and unique)
o {Email} (Every student has a unique email)

Note: A candidate key must be minimal, meaning if any attribute is removed, it should not
remain a super key.

3. Primary Key

A primary key is the chosen candidate key used to uniquely identify records in a table. It
cannot contain NULL values.

Example (From Student Table)

StudentID (Primary Key) Name Address Phone Email


S101 Ali Khan Lahore 03123456789 [email protected]
S102 Sara Malik Islamabad 03219876543 [email protected]

Here, StudentID is chosen as the Primary Key, as it uniquely identifies each student.

4. Composite Key

A composite key is a key consisting of two or more attributes that together uniquely
identify a record.

Example (Course Enrollment Table)

StudentID CourseID Semester


S101 CSE101 Spring 2025
S101 CSE102 Spring 2025
S102 CSE101 Spring 2025

Here, neither StudentID nor CourseID alone is unique, but together they form a Composite
Key:
Composite Key = {StudentID, CourseID}

5. Alternate Key

An alternate key is a candidate key that is not chosen as the primary key.

Example (From Student Table)


 Candidate Keys: {StudentID}, {Email}
 Primary Key Chosen: StudentID
 Alternate Key: Email

6. Foreign Key

A foreign key is an attribute in one table that refers to the primary key of another table.

Example

Consider two tables:

 Student Table (Primary Key: StudentID)


 Course Enrollment Table (Foreign Key: StudentID)

Student Table

StudentID (Primary Key) Name


S101 Ali Khan
S102 Sara Malik

Course Enrollment Table

EnrollmentID StudentID (Foreign Key) CourseID


1 S101 CSE101
2 S102 CSE102

Here, StudentID in the Course Enrollment Table is a Foreign Key referencing the Primary
Key in the Student Table.

7. Secondary Key

A secondary key is used for searching records but does not necessarily have unique values.

Example (From Student Table)

If we often search students by Address, then Address can be a Secondary Key, even though
it is not unique.

Summary Table
Key Type Definition Example
A set of attributes that uniquely identify {StudentID, Name},
Super Key
records. {StudentID, Email}
Candidate
A minimal super key with no extra attributes. {StudentID}, {Email}
Key
The selected candidate key for uniquely
Primary Key {StudentID}
identifying records.
Composite
A key consisting of multiple attributes. {StudentID, CourseID}
Key
Alternate Key A candidate key not chosen as the primary key. {Email}
A key in one table that references a primary {StudentID} in Course
Foreign Key
key in another table. Enrollment Table
Secondary A key used for searching records but not
{Address}
Key necessarily unique.

Conclusion

 Primary keys ensure uniqueness.


 Foreign keys maintain relationships between tables.
 Super keys are any unique combinations.
 Candidate keys are minimal unique keys.
 Composite keys use multiple attributes.
 Alternate keys are unused candidate keys.
 Secondary keys help in searching.

Here are some questions with answers based on Lecture 9: Relationships in Database
Management System (DBMS).

1. What are relationships in a Database Management System (DBMS)?

Answer: Relationships are the connections and interactions between entity instances. For
example, a Student and a Class can be linked through an Enroll relationship.

2. How can we identify relationships in a database?

Answer: Relationships can be identified by examining how different entity types interact. If
an association does not have a proper name, abbreviations or participant names can be
used.

3. How do we name relationships in a database?


Answer:

 If a clear name is available, it should be used (e.g., ENROLL for a student-class


relationship).
 If there is no proper name, abbreviations can be used (e.g., STD_CLS for Student-
Class).

4. What is the symbol used to represent relationships in an ER diagram?

Answer: A diamond shape is used to represent relationships between entities in an Entity-


Relationship (ER) diagram.

5. What is a relationship type in DBMS?

Answer: A relationship type is an abstraction of a relationship. It describes the role and


connection between different entity types.

6. What are participants in a relationship?

Answer: The entities involved in a relationship are called participants. For example, in the
Student-Class relationship, the participants are Student and Class.

7. What are the different types of relationships in DBMS?

Answer: Relationships can be categorized as:

1. Binary Relationship – Links two entity types (e.g., Student-Class).


2. Ternary Relationship – Involves three entity types (e.g., Student-Course-Faculty).
3. Unary Relationship – An entity is linked with itself (e.g., Employee-Manager).

8. What is a Binary Relationship? Provide an example.

Answer: A Binary Relationship is a relationship between two entities.

 Example:

o STUDENT - COURSE (A student enrolls in a course).


o BOOK - STUDENT (A student borrows a book).
o EMPLOYEE - PROJECT (An employee is assigned to a project).
9. What is a Ternary Relationship? Provide an example.

Answer: A Ternary Relationship involves three entities.

 Example:

o STUDENT - COURSE - FACULTY (A faculty member teaches a student in a


course).
o EMPLOYEE - PROJECT - SKILL (An employee with a specific skill is assigned to a
project).

10. How are relationship instances represented in DBMS?

Answer: Relationship instances can be represented in an ordered pair or tuple format.

 Binary Relationship Example:


{(S1001, OS), (S1020, DS), (S1002, DS), (S1058, NW)}
 Ternary Relationship Example:
{(S1013, MCS4, Adnan), (S1023, MCS3, Fasih)}

11. What are attributes of relationships in DBMS?

Answer: Relationships can have descriptive attributes that provide additional information.

 Example: In a STUDENT - COURSE relationship, the attribute GRADE can store the
student's grade in the course.

12. What is a Unary Relationship? Provide an example.

Answer: A Unary Relationship (also called a recursive relationship) is when an entity is


related to itself.

 Example:

o STUDENT - ROOMMATE (A student is assigned a roommate, who is also a


student).
o EMPLOYEE - MANAGER (An employee reports to another employee as their
manager).
13. What is Cardinality in a relationship?

Answer: Cardinality defines the number of instances of one entity type that can be
associated with instances of another entity type.

14. What are the types of cardinality in DBMS?

Answer:

1. One-to-One (1:1) – Each entity in A is related to at most one entity in B.

o Example: A Department has one Chairperson.

2. One-to-Many (1:M) or Many-to-One (M:1) – One entity in A is related to many


entities in B (or vice versa).

o Example: A Department has many Employees.

3. Many-to-Many (M:N) – Many entities in A are related to many entities in B.

o Example: Projects are assigned to multiple Employees, and Employees work


on multiple Projects.

15. Provide an example of One-to-One, One-to-Many, and Many-to-Many relationships.

Answer:

Cardinality Example
One-to-One (1:1) DEPARTMENT - CHAIRPERSON (Each department has one chairperson).
One-to-Many
EMPLOYEE - DEPARTMENT (Each department has many employees).
(1:M)
Many-to-Many PROJECT - EMPLOYEE (Employees work on multiple projects, and
(M:N) projects have multiple employees).

You might also like