Database notes
Database notes
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
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:
Disadvantages:
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).
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.
Answer:
Data Independence refers to the ability to change the database schema without affecting
the application programs or user interfaces.
Answer:
1.
2.
3.
4.
5.
6.
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.) |
Answer:
Answer:
The External View is the way users perceive the database, limiting access to only relevant
data.
Characteristics:
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.
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:
Answer:
The Internal Level (Physical Level) deals with how data is physically stored on the system.
Characteristics:
Example:
Answer:
1.
Application Programmers:
2.
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).
1.
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.
8.
9.
10.
1.
2.
3.
4.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
1.
2.
3.
4.
1. Entities
2. Attributes
3. Relationships
5.
6.
7.
8.
9.
10.
11.
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.
14.
16.
17.
18.
19.
20.
1. Explain the concept of weak and strong entity types with examples.
Answer should include:
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.
2.
3.
4.
1. Super Key
2. Candidate Key
3. Primary Key
4. Secondary Key
5. Alternate Key
5.
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.
10.
11.
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.
14.
15.
16.
17.
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.
1.
2.
3.
Differentiate between Super Key, Candidate Key, and Primary Key with examples.
Answer should cover:
4.
5.
Draw an E-R diagram showing different key attributes for a Student database.
Answer should include:
6.
7.
Why are keys important in a relational database? Explain with examples.
Answer should include:
8.
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
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.
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.
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.
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.
6. Foreign Key
A foreign key is an attribute in one table that refers to the primary key of another table.
Example
Student Table
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.
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
Here are some questions with answers based on Lecture 9: Relationships in 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.
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.
Answer: The entities involved in a relationship are called participants. For example, in the
Student-Class relationship, the participants are Student and Class.
Example:
Example:
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.
Example:
Answer: Cardinality defines the number of instances of one entity type that can be
associated with instances of another entity type.
Answer:
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).