We've moved! — MindVault360 is now SrcForge. Better design, more content & premium notes.

Visit SrcForge →

MindVault360 has moved!

We've upgraded to SrcForge — a faster, more professional platform with better content, premium notes, and a modern design.

Visit us at SrcForge

Monday, February 3, 2025

ER Model

 

Entity-Relationship (ER) Model

The ER model is widely used for database design as it visually represents how data is structured and related. It consists of a collection of entities (real-world objects) and the relationships between them.

Each entity in the model is connected to others through conditions and dependencies, meaning one entity may depend on another. The ER model helps in designing a clear and logical structure before implementing the database.

Basic Concepts of ER Modeling

The Entity-Relationship (ER) Model is built on three fundamental concepts:

  1. Entity or Entity Type

  2. Attributes

  3. Relationship

These basic concepts help in creating an ER diagram which visually represents the structure and relationships within a database, aiding in database design and understanding.


Entity or Entity Type

An Entity represents a real-world object or concept that is easily identifiable. It could be a physical object or an abstract concept.

For example, in a company’s database, Employee, HR, and Manager are considered entities. Each entity will have its own set of attributes.

In an ER diagram, an entity is typically represented by a rectangular box.


Types of Entity

  1. Strong Entity
  2. Weak Entity
  3. Entity Instance

Strong Entity

A Strong Entity is an entity that does not depend on any other entity in the database or schema for its identification. It has a primary key, which is a unique identifier that no other entity shares.

For example, in a Student entity, the Roll Number can be the primary key since it uniquely identifies each student. This makes the Student a strong entity, as the Roll Number will always be unique and independent from other entities.

In an ER diagram, a strong entity is represented by a single rectangle.

Weak Entity

A Weak Entity is an entity that depends on another entity for its identification and does not have its own primary key, unlike a Strong Entity. It relies on the primary key of another entity (often called the owner entity) to form a unique identifier.

In an ER diagram, a weak entity is represented by a double rectangle.

For example, in a Marks entity, there may be no unique ID, and its existence depends on another entity, such as the Student entity. The Marks entity cannot be uniquely identified without referencing the Student entity.



Entity Instance

An Entity Instance refers to a specific example of an entity. It represents a single occurrence of an entity type.

For example, if Animal is an entity, its instances could be Dog, Cat, Cow, etc. Each of these instances belongs to the Animal entity category.

In a database, entity instances are the actual data values stored for an entity.


Attributes

An Attribute is a piece of information that describes or defines an entity. It provides details about an entity by quantifying, qualifying, classifying, or specifying its characteristics. Attributes can hold single values, which may be numbers, characters, or strings.

Types of Attributes

  1. Key Attribute
  2. Simple Attribute
  3. Composite Attribute
  4. Single-Valued Attribute
  5. Multi-Valued Attribute

Key Attribute

A Key Attribute is an attribute that uniquely identifies an entity within a database. It ensures that each instance of an entity is distinct from all others.

For example, in a Student entity, Roll Number is a key attribute because it uniquely identifies each student.

Simple Attribute

A Simple Attribute is an attribute that cannot be divided into smaller parts. It holds a single, indivisible value for an entity.

For example, in an Employee entity, Name is a simple attribute because it is stored as a single value without further division.


Composite Attribute

A Composite Attribute is an attribute that can be divided into smaller sub-attributes while still retaining its meaning.

For example, in an Employee entity, the Name attribute can be broken down into First Name and Last Name. Here, Name is a composite attribute because it consists of multiple meaningful sub-parts.


Single-Valued Attribute

A Single-Valued Attribute holds only one value for each entity instance and cannot have multiple values.

For example, in a Person entity, Age is a single-valued attribute because a person can have only one age at a given time.




Multi-Valued Attribute

A Multi-Valued Attribute is an attribute that can hold multiple values for a single entity instance.

For example, in a Person entity, Degree is a multi-valued attribute because a person can have multiple degrees (e.g., B.Sc., M.Sc., Ph.D.).


Relationship Types in ER Model

In the ER Model, relationships define how two entities are connected. There are three main types of relationships:

  1. One-to-One (1:1) Relationship

    • A single instance of Entity A is associated with at most one instance of Entity B, and vice versa.
    • Example: A person and their passport (Each person has one passport, and each passport belongs to one person).
  2. One-to-Many (1:N) Relationship

    • A single instance of Entity A can be related to multiple instances of Entity B, but each instance of Entity B is associated with at most one instance of Entity A.
    • Example: A teacher and students (One teacher can teach multiple students, but each student has only one assigned teacher).
  3. Many-to-Many (M:N) Relationship

    • Multiple instances of Entity A can be related to multiple instances of Entity B.
    • Example: Students and courses (A student can enroll in multiple courses, and each course can have multiple students).

Practical Usage

  • One-to-One relationships are rare in real-world database design.
  • One-to-Many and Many-to-Many relationships are commonly used.
  • In relational databases, Many-to-Many relationships are usually converted into One-to-Many relationships using a junction table (or bridge table) for proper database normalization.

Relationship Instance

A Relationship Instance is a specific occurrence of a relationship between two entities in an RDBMS. It represents a finite set of tuples (rows) in a relational table, ensuring that there are no duplicates.

For example, if "Works-For" is the relationship between the Employee entity and the Department entity, then:

  • Ram works for the Computer Science department
  • Shyam works for the Electrical department

These are relationship instances of the "Works-For" relationship.

Degree of a Relationship

The Degree of a Relationship refers to the number of entity types involved in a relationship. It can be classified as:

  1. Unary Relationship (Degree = 1)

    • A relationship where an entity is related to itself.
    • Example: Manager-of → An employee manages other employees within the same entity set.
  2. Binary Relationship (Degree = 2)

    • A relationship between two entities.
    • Example: Works-For → An employee works for a department.
  3. Ternary Relationship (Degree = 3)

    • A relationship involving three entities.
    • Example: Purchases → A customer buys an item from a shopkeeper.

In real-world database design, binary relationships are the most common, while ternary and higher-degree relationships are often broken down into multiple binary relationships for better normalization.


Cardinality

Cardinality defines the number of items (or entities) that must be involved in a relationship between two sets of entities. It represents how many instances of one entity are related to instances of another entity in a relationship.

The three common classifications of cardinality are:

  1. One-to-One (1:1)

    • Each instance of Entity A is associated with exactly one instance of Entity B, and vice versa.

        In the above example we have two entities Person and Vehicle. If we consider a person driving vehicle, then we have one-to-one relationship between Person and Vehicle.
  1. One-to-Many (1:N)

    • One instance of Entity A can be associated with multiple instances of Entity B, but each instance of Entity B is associated with only one instance of Entity A.

In the above example, Customer places the Order is a one-to-many relationship. Here the customer can place multiple orders and the order is related to only one customer. 
  1. Many-to-Many (M:N)

    • Multiple instances of Entity A can be related to multiple instances of Entity B, and vice versa.
The example of many-to-many relationship is Students registering the Courses. A student can register more than one courses and A course can be registered by many students. Hence it is many-to-many

Cardinality helps define the rules for how entities interact with each other, ensuring referential integrity and appropriate relationships in a database schema.





← Back Next →

Labels:

Relational Database Management System

 A Relational Database is any database structured based on the relational data model. A Relational Database Management System (RDBMS) is the software used to manage these databases.

RDBMS is the foundation of SQL and serves as the backbone for modern database systems like MySQL, Oracle, and Microsoft Access.

Key concepts in RDBMS include Databases, Tables, Tuples (Rows), Attributes (Columns), Schemas, and Keys, which are essential for organizing and managing data efficiently. These concepts are commonly referred to as RDBMS Jargons and are fundamental to understanding relational databases.


RDBMS Jargons:

Relational Databases

One of the most popular Relational Databases is MySQL, an open-source SQL database that runs on multiple platforms, including Windows, Linux, and macOS. Other widely used relational databases include Oracle, Microsoft SQL Server, and MS Access.

Key Features of RDBMS

  • High Availability – Ensures continuous access to data
  • High Performance – Optimized for speed and efficiency
  • Robust Transactions – Supports reliable and secure data operations
  • Easy Management – Simplifies database administration
  • Cost-Effective – Lower costs compared to some proprietary solutions

Table in a Relational Database

In a relational database, a table is a structured collection of data organized into rows and columns. It provides a simple and intuitive way to represent relationships between data.

While a true relation in database theory does not allow duplicate rows, a table in an RDBMS can contain duplicates unless constraints like primary keys are applied to enforce uniqueness.



Column in a Relational Database

A table in a relational database consists of multiple rows and columns. Each column represents a specific type of data and is also referred to as an attribute.

For example, in an Employee table, common attributes might include ID, Name, Age, and Salary. Each attribute is designed to store values of a specific data type, known as the Attribute Domain. For instance, the Name column would store only text, not numbers.

In database terminology, a column or attribute is a vertical entity within a table that ensures data is stored in a structured and organized manner.



Primary Key and Alternate Key

A Primary Key is a candidate key selected to uniquely identify each row (record) in a table. Every row must have a unique and non-null value for its primary key.

If a table has multiple candidate keys, the ones not chosen as the primary key are called Alternate Keys.

When a primary key consists of multiple attributes (columns) instead of just one, it is known as a Composite Primary Key. This is used when a single column is not sufficient to uniquely identify records.

Foreign Key in a Relational Database

A Foreign Key is a column (or set of columns) in one table that acts as a reference to the Primary Key of another table. It establishes a relationship between the two tables, ensuring referential integrity.

  • A foreign key must match the entire primary key of the referenced table. If the primary key is composite (consists of multiple attributes), the foreign key must also be composite.
  • Unlike primary keys, foreign key values do not have to be unique and can contain null values.
  • In a composite foreign key, either all attributes must be null, or none can be null—partial null values are not allowed.

Super Key and Candidate Key

A Super Key is an attribute or a set of attributes that uniquely identifies each row (tuple) in a table.

From the set of super keys, the minimal keys (i.e., those without unnecessary attributes) are selected as Candidate Keys. A Candidate Key is a super key that contains no redundant attributes.

Since a Primary Key is chosen from the candidate keys, every primary key is a candidate key, but not every candidate key is a primary key.

In short:

  • Super Key → Can have extra attributes.
  • Candidate Key → A minimal super key (no extra attributes).
  • Primary Key → A chosen candidate key for uniquely identifying rows.

Composite Key (Compound Key)

A Composite Key (also called a Compound Key) is a key that consists of two or more attributes to uniquely identify rows in a table. It is used when a single attribute is not enough to ensure uniqueness.

For example, in a Student_Course table that tracks which students are enrolled in which courses, neither Student_ID nor Course_ID alone may be unique, but together (Student_ID, Course_ID) form a composite key to uniquely identify each record.









← Back Next →

Labels:

Tuesday, December 17, 2024

Database Model

Relational and object-relational models were the basis for the development of database technology. The principal Below is a list of database models: 

Hierarchical Database model:

The famous Hierarchical database model was IMS(Information Management System). IBM's initial database management system. Each entry in this model contains information on the parent-child relationship in the form of a tree. In a relational model, the collection of records is referred to as record types, which are the same as tables. Each record is equivalent to a row.


There are numerous benefits to the aforementioned paradigm, including reduced redundant data, effective search, data integrity, and security.
A few other drawbacks of this approach are its complexity in implementation and its inability to manage many-to-many interactions.

Network Model:
Honeywell's IDS (Integrated Data Store) was the first network data model to be created. The network model is comparable to the hierarchical model, with the exception that each member may have several owners. The management of many-to-many relationships is improved. The three database components—Network schema, Sub schema, and Language for data management—were identified by this paradigm.



  • Network schema – schema defines all about the structure of the database.
  • Sub schema – control on views of the database for the user
  • Language – basic process for accessing the database.
This model's main benefits are its capacity to manage a wider variety of relationship kinds, as well as its ease of access, independence, and data integrity. The network model's design and maintenance challenges are its drawback.

Relational Model:
A couple of the commercial relational models in use include Oracle and DB2. Instance and schema are the two terms used to define a relational model.



  • Instance – A table consisting of rows and columns
  • Schema – Specifies the structure including name and type of each column.
 A relation (table) consists of unique attributes (columns) and tuples (rows).

Object-oriented database model:
This paradigm combines database technologies with the ideas of object-oriented programming, or OOP. In practice, this model forms the foundation of the relational model. Objects are tiny, reusable pieces of software used in this model. An object-oriented database houses these. This model effectively handles a wide variety of data formats. Furthermore, OOP's ideas are effective in handling complicated behaviors.




← Back Next →

Labels:

Tuesday, December 10, 2024

DBMS Introduction

Let's examine what DBMS

  • which stands for Database Management System, actually means. Data is stored, retrieved, and managed in a database. 
  • Then, what is a data? Databases contain everything from complex data, like astronomical data handled by scientists, to meaningful information, like your name and favorite color. A collection of applications for managing data, including storing, retrieving, filtering, and other functions, is referred to as a management system. 
  • Several well-known database management systems include Oracle, MySQL, and others. Among the noteworthy characteristics of a strong database management system are its ability to protect data and make it easy for users to use.

Definition: “A database management system (DBMS) is system soft ware for creating and managing databases. Th e DBMS provides users and programmers with a systematic way to create, retrieve, update and manage data.”

What kind of information is kept in a database?
Only related data would be grouped together and stored in a database under a single group name called a table. This facilitates the process of determining which data is kept where and under what name.

Evolution of DBMS:

The idea of storing data in many formats dates back more than 40 years. In the past, they stored the data using punched card technology. Files were then used. File systems were regarded as database systems' forerunners. The file system had multiple access techniques, including sequential, random, and indexed access.

The file system featured additional restrictions, such as

Data Duplication: several resources use the same data for processing, resulting in several copies of the same data that waste space.

High Maintenance: High maintenance costs are required for access control and data consistency verification.

Security: less protection for the data.

So database systems became popular to overcome the above limitations of file system.

DBMS Concepts:
Relational Database Management System (RDBMS) and Object Database Management System (ODBMS) are two examples of the few standards that apply to all types of database management systems. The two fundamental ideas listed here are followed by all DBMS.

Atomicity, Consistency, Isolation, and Durability are the acronyms for ACID Properties. 

  • Atomicity updates database data for the user doing the update process by adhering to the maxim "All or Nothing." This update process, known as a transaction, either commits (updating successfully) or aborts (updating unsuccessfully).
  • Consistency guarantees that variations in data values are constant at all times. This property contributes to the transaction's success. 
  • Concurrent transactions require isolation properties. A concurrent transaction is one in which several people access the same object simultaneously to complete the transaction. Transactions are serialized and segregated from other users to avoid conflicts during database updates. Another name for this is the Degree of Consistency. 
  • The capacity of the system to restore all completed transactions in the event of a storage or system failure is known as durability.
The DBMS's data sharing method is called Concurrency Control and Locking. Proper access control is required when numerous users share the same data, and locking is used to limit who has the ability to change an application's data item.
← Back Next →

Labels: