Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Databasenotesclass

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 41

What is Database

The database is a collection of inter-related data which is used to retrieve, insert and
delete the data efficiently. It is also used to organize the data in the form of a table,
schema, views, and reports, etc.

For example: The college Database organizes the data about the admin, staff,
students and faculty etc.

Using the database, you can easily retrieve, insert, and delete the information.`

Database Management System


o Database management system is a software which is used to manage the
database. For example: MySQL, Oracle, etc are a very popular commercial
database which is used in different applications.
o DBMS provides an interface to perform various operations like database
creation, storing data in it, updating data, creating a table in the database and
a lot more.
o It provides protection and security to the database. In the case of multiple
users, it also maintains data consistency.

DBMS allows users the following tasks:

o Data Definition: It is used for creation, modification, and removal of


definition that defines the organization of data in the database.
o Data Updation: It is used for the insertion, modification, and deletion of the
actual data in the database.
o Data Retrieval: It is used to retrieve the data from the database which can be
used by applications for various purposes.
o User Administration: It is used for registering and monitoring users, maintain
data integrity, enforcing data security, dealing with concurrency control,
monitoring performance and recovering information corrupted by unexpected
failure.

Characteristics of DBMS
o It uses a digital repository established on a server to store and manage the
information.
o It can provide a clear and logical view of the process that manipulates data.
o DBMS contains automatic backup and recovery procedures.
o It contains ACID properties which maintain data in a healthy state in case of
failure.
o It can reduce the complex relationship between data.
o It is used to support manipulation and processing of data.
o It is used to provide security of data.
o It can view the database from different viewpoints according to the
requirements of the user.

Advantages of DBMS
o Controls database redundancy: It can control data redundancy because it
stores all the data in one single database file and that recorded data is placed
in the database.
o Data sharing: In DBMS, the authorized users of an organization can share the
data among multiple users.
o Easily Maintenance: It can be easily maintainable due to the centralized
nature of the database system.
o Reduce time: It reduces development time and maintenance need.
o Backup: It provides backup and recovery subsystems which create automatic
backup of data from hardware and software failures and restores the data if
required.
o multiple user interface: It provides different types of user interfaces like
graphical user interfaces, application program interfaces

Disadvantages of DBMS
o Cost of Hardware and Software: It requires a high speed of data processor
and large memory size to run DBMS software.
o Size: It occupies a large space of disks and large memory to run them
efficiently.
o Complexity: Database system creates additional complexity and
requirements.
o Higher impact of failure: Failure is highly impacted the database because in
most of the organization, all the data stored in a single database and if the
database is damaged due to electric failure or database corruption then the
data may be lost forever.

Data Independence
o Data independence can be explained using the three-schema architecture.
o Data independence refers characteristic of being able to modify the schema at one
level of the database system without altering the schema at the next higher level.

There are two types of data independence:

1. Logical Data Independence


o Logical data independence refers characteristic of being able to change the
conceptual schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual
view.
o If we do any changes in the conceptual view of the data, then the user view of the
data would not be affected.
o Logical data independence occurs at the user interface level.

2. Physical Data Independence


o Physical data independence can be defined as the capacity to change the internal
schema without having to change the conceptual schema.
o If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
o Physical data independence is used to separate conceptual levels from the internal
levels.
o Physical data independence occurs at the logical interface level.
Importance of Data Independence in DBMS
 It encourages you to improve the information's quality

 Database disjointness is infinitely reduced

 In application programs, you do not need to change the information


structure

 It allows designers to focus on the overall structure of the Database


rather than obsessing over the interior usage

 Making effective physical modifications is predicted to boost the


framework's exhibition

What is an example of data independence in DBMS?


An example of data independence in DBMS is when a database administrator
modifies the physical storage structure of the database, such as moving data to a
different disk or changing the indexing strategy, without affecting the application
programs that use the database.
Difference between Hierarchical, Network and
Relational Data Model



1. Hierarchical Data Model:
Hierarchical data model is the oldest type of the data model. It was developed by IBM
in 1968. It organizes data in the tree-like structure. Hierarchical model consists of the
following :
 It contains nodes which are connected by branches.
 The topmost node is called the root node.
 If there are multiple nodes appear at the top level, then these can be called
as root segments.
 Each node has exactly one parent.
 One parent may have many child.

Figure – Hierarchical Data Model


In the above figure, Electronics is the root node which has two children i.e.
Televisions and Portable Electronics. These two has further children for which they
act as parent. For example: Television has children as Tube, LCD and Plasma, for
these three Television act as parent. It follows one to many relationship.
2. Network Data Model:
It is the advance version of the hierarchical data model. To organize data it uses
directed graphs instead of the tree-structure. In this child can have more than one
parent. It uses the concept of the two data structures i.e. Records and Sets.
Figure – Network Data Model
In the above figure, Project is the root node which has two children i.e. Project 1 and
Project 2. Project 1 has 3 children and Project 2 has 2 children. Total there are 5
children i.e Department A, Department B and Department C, they are network related
children as we said that this model can have more than one parent. So, for the
Department B and Department C have two parents i.e. Project 1 and Project 2.
3. Relational Data Model:
The relational data model was developed by E.F. Codd in 1970. There are no physical
links as they are in the hierarchical data model. Following are the properties of the
relational data model :
 Data is represented in the form of table only.
 It deals only with the data not with the physical structure.
 It provides information regarding metadata.
 At the intersection of row and column there will be only one value for the
tuple.
 It provides a way to handle the queries with ease.
Figure – Relational Data Model
Difference between Hierarchical, Network and Relational Data Model:
S. Hierarchical Data Relational Data
No. Model Network Data Model Model

In this model, to store It organizes records in


data hierarchy method It organizes records to the form of table and
1. is used. It is the oldest one another through links relationship between
method and not in use or pointers. tables are set using
today. common fields.

To organize records, it It organizes records in the It organizes records in


2.
uses tree structure. form of directed graphs. the form of tables.

In addition to 1:1 and


In addition to 1:1 and 1:n
It implements 1:1 and 1:n it also implements
3. it also implements many
1:n relations. many to many
to many relationships.
relationships.
S. Hierarchical Data Relational Data
No. Model Network Data Model Model

The logical
Pointers are used to
A linked list is used to representation is used
establish relationships
4. establish a relationship with rows and columns
among records
among records physically. to depict relationship
physically.
among records.

Insertion anomaly exits


in this model i.e. child
There is no insertion There is no insertion
5. node cannot be
anomaly. anomaly.
inserted without the
parent node.

Deletion anomaly exists


in this model i.e. it is There is no deletion There is no deletion
6.
difficult to delete the anomaly. anomaly.
parent node.

Update leads to Updating a record is


inconsistency problems easy and simple with
No such problem as only
because of the the process of
7. one instance of records
existence of multiple normalization, the
exist.
instances of a child redundant data gets
record. removed.

There is partial data


This model lacks data This model provides
8. independence in this
independence. data independence.
model.

No such facility for No such facility for


SQL-based declarative
9. querying database is querying database is
querying is supported.
supported. supported.
S. Hierarchical Data Relational Data
No. Model Network Data Model Model

It is used to access the It is used to access the It is used to access the


10. data which is complex data which is complex data which is complex
and asymmetric. and symmetric. and symmetric.

Difficult to design a
database and manipulate It is easy to
Difficult to design a
a database because of its comprehend due to
11. database because of its
complexity. Hence, it concealed physical level
complexity.
imposes a burden on the details from end-users.
programmer.

It is flexible as
It is flexible as compared
12. It is less flexible. compared to the
to the hierarchical model.
hierarchical model.

VAX-DBMS, DMS-1100 of
It is mostly used in real
&XML and XAML use UNIVAC and
13. world applications.
this model. SUPRADBMS’s use this
Oracle, SQL.
model.

ER (Entity Relationship) Diagram in


DBMS

o ER model stands for an Entity-Relationship model. It is a high-level data model. This


model is used to define the data elements and relationship for a specified system.
o It develops a conceptual design for the database. It also develops a very simple and
easy to design view of data.
o In ER modeling, the database structure is portrayed as a diagram called an entity-
relationship diagram.

For example, Suppose we design a school database. In this database, the student
will be an entity with attributes like address, name, id, age, etc. The address can be
another entity with attributes like city, street name, pin code, etc and there will be a
relationship between them.

Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can
be represented as rectangles.

Consider an organization as an example- manager, product, employee, department


etc. can be taken as an entity.

a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity
doesn't contain any key attribute of its own. The weak entity is represented by a
double rectangle.

2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to
represent an attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.

a. Key Attribute

The key attribute is used to represent the main characteristics of an entity. It


represents a primary key. The key attribute is represented by an ellipse with the text
underlined.
b. Composite Attribute

An attribute that composed of many other attributes is known as a composite


attribute. The composite attribute is represented by an ellipse, and those ellipses are
connected with an ellipse.

c. Multivalued Attribute

An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.
d. Derived Attribute

An attribute that can be derived from other attribute is known as a derived attribute.
It can be represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from another
attribute like Date of birth.

3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus
is used to represent the relationship.
Types of relationship are as follows:

a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is
known as one to one relationship.

For example, A female can marry to one male, and a male can marry to one female.

b. One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then this is known as a one-to-
many relationship.

For example, Scientist can invent many inventions, but the invention is done by the
only specific scientist.

c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an
entity on the right associates with the relationship then it is known as a many-to-one
relationship.

For example, Student enrolls for only one course, but a course can have many
students.

d. Many-to-many relationship

When more than one instance of the entity on the left, and more than one instance
of an entity on the right associates with the relationship then it is known as a many-
to-many relationship.

For example, Employee can assign by many projects and project can have many
employees.

Cardinality in DBMS (Mapping


Constraints)
DBMS
DBMS stands for Database Management System, which is a tool, or a software used
to do various operations on a Database like the Creation of the Database, Deletion of
the Database, or Updating the current Database. To simplify processing and data
querying, the most popular types of Databases currently in use typically model their
data as rows and columns in a set of tables. The data may then be handled, updated,
regulated, and structured with ease. For writing and querying data, most Databases
employ Structured Query Language (SQL).

Cardinality
Cardinality means how the entities are arranged to each other or what is the
relationship structure between entities in a relationship set. In a Database
Management System, Cardinality represents a number that denotes how many times
an entity is participating with another entity in a relationship set. The Cardinality of
DBMS is a very important attribute in representing the structure of a Database. In a
table, the number of rows or tuples represents the Cardinality.

Cardinality Ratio
Cardinality ratio is also called Cardinality Mapping, which represents the mapping
of one entity set to another entity set in a relationship set. We generally take the
example of a binary relationship set where two entities are mapped to each other.

Cardinality is very important in the Database of various businesses. For example, if we


want to track the purchase history of each customer then we can use the one-to-
many cardinality to find the data of a specific customer. The Cardinality model can be
used in Databases by Database Managers for a variety of purposes, but corporations
often use it to evaluate customer or inventory data.

There are four types of Cardinality Mapping in Database Management Systems:

1. One to one
2. Many to one
3. One to many
4. Many to many

One to One
One to one cardinality is represented by a 1:1 symbol. In this, there is at most one
relationship from one entity to another entity. There are a lot of examples of one-to-
one cardinality in real life databases.

For example, one student can have only one student id, and one student id can
belong to only one student. So, the relationship mapping between student and
student id will be one to one cardinality mapping.
Another example is the relationship between the director of the school and the
school because one school can have a maximum of one director, and one director
can belong to only one school.

Note: it is not necessary that there would be a mapping for all entities in an entity
set in one-to-one cardinality. Some entities cannot participate in the mapping.

Many to One Cardinality:


In many to one cardinality mapping, from set 1, there can be multiple sets that can
make relationships with a single entity of set 2. Or we can also describe it as from set
2, and one entity can make a relationship with more than one entity of set 1.

One to one Cardinality is the subset of Many to one Cardinality. It can be represented
by M:1.

For example, there are multiple patients in a hospital who are served by a single
doctor, so the relationship between patients and doctors can be represented by
Many to one Cardinality.
One to Many Cardinalities:
In One-to-many cardinality mapping, from set 1, there can be a maximum single set
that can make relationships with a single or more than one entity of set 2. Or we can
also describe it as from set 2, more than one entity can make a relationship with only
one entity of set 1.

One to one cardinality is the subset of One-to-many Cardinality. It can be


represented by 1: M.

For Example, in a hospital, there can be various compounders, so the relationship


between the hospital and compounders can be mapped through One-to-many
Cardinality.
Many to Many Cardinalities:
In many, many cardinalities mapping, there can be one or more than one entity that
can associate with one or more than one entity of set 2. In the same way from the
end of set 2, one or more than one entity can make a relation with one or more than
one entity of set 1.

It is represented by M: N or N: M.

One to one cardinality, One to many cardinalities, and Many to one cardinality is the
subset of the many to many cardinalities.

For Example, in a college, multiple students can work on a single project, and a
single student can also work on multiple projects. So, the relationship between the
project and the student can be represented by many to many cardinalities.
Appropriate Mapping Cardinality
Evidently, the real-world context in which the relation set is modeled determines the
Appropriate Mapping Cardinality for a specific relation set.

o We can combine relational tables with many involved tables if the Cardinality is
one-to-many or many-to-one.
o One entity can be combined with a relation table if it has a one-to-one
relationship and total participation, and two entities can be combined with
their relation to form a single table if both of them have total participation.
o We cannot mix any two tables if the Cardinality is many-to-many.

Keys
o Keys play an important role in the relational database.
o It is used to uniquely identify any record or row of data from the table. It is also used
to establish and identify relationships between tables.
For example, ID is used as a key in the Student table because it is unique for each
student. In the PERSON table, passport_number, license_number, SSN are keys since
they are unique for each person.

Types of keys:

1. Primary key
o It is the first key used to identify one and only one instance of an entity uniquely. An
entity can contain multiple keys, as we saw in the PERSON table. The key which is
most suitable from those lists becomes a primary key.
o In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary keys since they are also unique.
o For each entity, the primary key selection is based on requirements and developers.

2. Candidate key
o A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
o Except for the primary key, the remaining attributes are considered a candidate key.
The candidate keys are as strong as the primary key.

For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of
the attributes, like SSN, Passport_Number, License_Number, etc., are considered a
candidate key.
3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a
superset of a candidate key.

For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME),


the name of two employees can be the same, but their EMPLYEE_ID can't be the
same. Hence, this combination can also be a key.

The super key would be EMPLOYEE-ID (EMPLOYEE_ID, EMPLOYEE-NAME), etc.

4. Foreign key
o Foreign keys are the column of the table used to point to the primary key of another
table.
o Every employee works in a specific department in a company, and employee and
department are two different entities. So we can't store the department's information
in the employee table. That's why we link these two tables through the primary key of
one table.
o We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute
in the EMPLOYEE table.
o In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are
related.
5. Alternate key
There may be one or more attributes or a combination of attributes that uniquely
identify each tuple in a relation. These attributes or combinations of the attributes
are called the candidate keys. One key is chosen as the primary key from these
candidate keys, and the remaining candidate key, if it exists, is termed the alternate
key. In other words, the total number of the alternate keys is the total number of
candidate keys minus the primary key. The alternate key may or may not exist. If
there is only one candidate key in a relation, it does not have an alternate key.

For example, employee relation has two attributes, Employee_Id and PAN_No, that
act as candidate keys. In this relation, Employee_Id is chosen as the primary key, so
the other candidate key, PAN_No, acts as the Alternate key.

6. Composite key
Whenever a primary key consists of more than one attribute, it is known as a
composite key. This key is also known as Concatenated Key.
For example, in employee relations, we assume that an employee may be assigned
multiple roles, and an employee may work on multiple projects simultaneously. So
the primary key will be composed of all three attributes, namely Emp_ID, Emp_role,
and Proj_ID in combination. So these attributes act as a composite key since the
primary key comprises more than one attribute.

7. Artificial key
The key created using arbitrarily assigned data are known as artificial keys. These
keys are created when a primary key is large and complex and has no relationship
with many other relations. The data values of the artificial keys are usually numbered
in a serial order.

For example, the primary key, which is composed of Emp_ID, Emp_role, and Proj_ID,
is large in employee relations. So it would be better to add a new virtual attribute to
identify each tuple in the relation uniquely.
Generalization
o Generalization is like a bottom-up approach in which two or more entities of lower
level combine to form a higher level entity if they have some attributes in common.
o In generalization, an entity of a higher level can also combine with the entities of the
lower level to form a further higher level entity.
o Generalization is more like subclass and superclass system, but the only difference is
the approach. Generalization uses the bottom-up approach.
o In generalization, entities are combined to form a more generalized entity, i.e.,
subclasses are combined to make a superclass.

For example, Faculty and Student entities can be generalized and create a higher
level entity Person.
Specialization
o Specialization is a top-down approach, and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
o Specialization is used to identify the subset of an entity set that shares some
distinguishing characteristics.
o Normally, the superclass is defined first, the subclass and its related attributes are
defined next, and relationship set are then added.

For example: In an Employee management system, EMPLOYEE entity can be


specialized as TESTER or DEVELOPER based on what role they play in the company.

Aggregation
In aggregation, the relation between two entities is treated as a single entity. In
aggregation, relationship with its corresponding entities is aggregated into a higher
level entity.
For example: Center entity offers the Course entity act as a single entity in the
relationship which is in a relationship with another entity visitor. In the real world, if a
visitor visits a coaching center then he will never enquiry about the Course only or
just about the Center instead he will ask the enquiry about both.

Reduction of ER diagram to Table


The database can be represented using the notations, and these notations can be
reduced to a collection of tables.

In the database, every entity set or relationship set can be represented in tabular
form.

The ER diagram is given below:


There are some points for converting the ER diagram to the table:

o Entity type becomes a table.

In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms individual
tables.

o All single-valued attribute becomes a column for the table.

In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of


STUDENT table. Similarly, COURSE_NAME and COURSE_ID form the column of
COURSE table and so on.

o A key attribute of the entity type represented by the primary key.

In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and LECTURE_ID are


the key attribute of the entity.

o The multivalued attribute is represented by a separate table.


In the student table, a hobby is a multivalued attribute. So it is not possible to
represent multiple values in a single column of STUDENT table. Hence we create a
table STUD_HOBBY with column name STUDENT_ID and HOBBY. Using both the
column, we create a composite key.

o Composite attribute represented by components.

In the given ER diagram, student address is a composite attribute. It contains CITY,


PIN, DOOR#, STREET, and STATE. In the STUDENT table, these attributes can merge
as an individual column.

o Derived attributes are not considered in the table.

In the STUDENT table, Age is the derived attribute. It can be calculated at any point
of time by calculating the difference between current date and Date of Birth.

Using these rules, you can convert the ER diagram to tables and columns and assign
the mapping between the tables. Table structure for the given ER diagram is as
below:

Figure: Table structure


the advantages and
limitations of Entity-
Relationship (ER)
diagrams:
### Advantages:

1. **Clarity and Visualization**: ER diagrams provide a clear visual representation of


the database schema, making it easier for stakeholders to understand the structure
and relationships within the database.

2. **Simplicity**: ER diagrams use simple and intuitive notations, such as boxes for
entities, lines for relationships, and diamonds for attributes, making them accessible
to both technical and non-technical audiences.

3. **Communication Tool**: ER diagrams serve as a common language between


database designers, developers, and users, facilitating communication and
collaboration during the database design process.
4. **Database Design**: ER diagrams aid in the systematic design of databases by
helping to identify entities, attributes, and relationships early in the design process,
which can lead to more robust and efficient database structures.

5. **Normalization**: ER diagrams assist in the normalization process by highlighting


redundancy and dependencies within the database schema, thereby promoting the
creation of normalized database designs that minimize data redundancy and improve
data integrity.

6. **Blueprint for Implementation**: While ER diagrams focus on the conceptual and


logical levels of database design, they provide a blueprint for implementing the
database schema in a database management system (DBMS) by defining the entities,
attributes, and relationships that will be translated into database tables, columns, and
foreign key constraints.

### Limitations:

1. **Abstraction**: ER diagrams offer a high-level abstraction of the database schema,


which may oversimplify or omit certain complexities and details present in real-world
database systems.

2. **Ambiguity**: In complex systems, the interpretation of relationships and


attributes in an ER diagram can be ambiguous, leading to potential
misunderstandings or misinterpretations of the database structure.

3. **Dynamic Behavior**: ER diagrams primarily depict the static structure of a


database and do not capture dynamic aspects such as data changes over time,
system behaviors, or transactional processes.
4. **Lack of Operations**: ER diagrams do not explicitly represent database
operations or behaviors, such as data manipulation operations (e.g., INSERT, UPDATE,
DELETE) or transaction management.

5. **Scalability**: As the complexity of the database system increases, ER diagrams


can become unwieldy and difficult to manage, particularly for large databases with
numerous entities and relationships.

6. **Limited Expressiveness**: ER diagrams may lack the expressiveness to represent


certain advanced data modeling concepts comprehensively, such as inheritance
relationships, complex business rules, or constraints beyond primary keys and foreign
keys.

Despite these limitations, ER diagrams remain a valuable tool for database designers
to conceptualize, communicate, and design database systems effectively. They are
often supplemented with other modeling techniques and documentation to address
their shortcomings and provide a more comprehensive understanding of the
database design.

Enhanced ER Model
ER Diagram
ER diagram stands for Entity Relationship diagram. When we draw the relationships
between entities using a diagram, then it is called an entity relationship diagram. The
ER diagram is just for understanding the purpose of the database administrator. We
cannot use the ER diagram directly on the computer. ER diagrams are converted into
the tabular form then they are inserted into the computer using any query language.
In ER diagrams, we use attributes, entities, and the relationships between entities. We
use an oval shape to represent the entity and a diamond shape to represent the
relationships between entities.

Enhanced ER Diagram
It is getting harder and harder to apply the conventional ER paradigm for database
modeling as data complexity rises today. The existing ER model needs to be
enhanced or improved in order for it to better handle the complicated application in
order to reduce the modeling complexity.

The requirements and complexity of complicated databases are represented using


enhanced entity-relationship diagrams, which are sophisticated database diagrams
very similar to standard ER diagrams.

The SubClass and SuperClass, Specialization and Generalization, Union or Category,


Aggregation, etc., are displayed using this diagrammatic style.

o Generalization and Specialization

These are two normal kinds of relationships that were added to the normal ER model
for enhancement. These are inspired by the object-oriented paradigm, where we
divide the code into classes and objects, and in the same way, we have divided
entities into subclass and superclasses. Specialized classes are called subclasses, and
generalized classes are called superclasses or base classes. We can learn the concept
of subclass by 'IS-A' analysis. For example, 'Laptop IS-A computer.' Or 'Clerk IS-A
employee.'

In this relationship, one entity is a subclass or superclass of another entity. For


example, in a university, a faculty member or clerk is a specialized class of employees.
So an employee is a generalized class, and all others are its subclass.

We can draw the ER diagram for these relationships. Let's suppose we have a
superclass Employee and subclasses as a clerk, engineer, and lab assistant.
The Enhanced ER diagram of the above example will look like this:

In the above example, we have one superclass and three subclasses. Each subclass
inherits all the attributes from its superclass so that a lab assistant will have all its
attributes, like its name, salary, etc.

Constraints
There are two types of constraints on subclasses which are described below:

o Total or Partial:
A total subclass relationship is one where the union of all the subclasses is equal to
the superclass. It means if every superclass entity has some subclass entity, then it is
called a total subclass relationship. Let's suppose if the union of all the subclasses
( engineer, clerk, lab assistant) is equal to the total employee. Then the relationship is
total. In the above example, it is a total relationship.

If all the entities of a superclass are not associated with a subclass, then it is called a
partial subclass relationship.

o Overlapped or Disjoint:

If any entity from the superclass is associated with more than one subclass, then it is
known as overlapped subclassing, and if it is associated with zero or only one
subclass, then it is called disjoint subclassing.

Note: The above two constraints are independent of each other, and they follow
the transitive property.
Multiple Inheritance
When one subclass is associated with more than one superclass, then this
phenomenon is known as multiple inheritance. In multiple inheritance, the attributes
of the subclass will be the union of all the superclass attributes which are associated
with it. For example, a teacher is a subclass that can be associated with the superclass
of an employee and a superclass of faculty. In the same way, a monitor in the class
can be a subclass of a student superclass as well as an alumni superclass.

UNION
UNION is a different topic from subclassing. Let's suppose we have a vehicle
superclass, and we have two subclasses, car and bike. These two subclasses will
inherit the attributes from the vehicle superclass.

Now we have a UNION of those vehicles which are RTO registered, so we have a
UNION of cars and bikes, but they will inherit all the attributes from the vehicle
superclass.

In an Entity-Relationship (ER) diagram, specialization


and generalization are represented through
inheritance relationships between entity types. Here
are the constraints and characteristics of
specialization and generalization in an ER diagram
context:

Specialization:

1. **Disjointness Constraint**: Specialization involves dividing a superclass (or parent


entity) into two or more subclasses (or child entities) that are disjoint, meaning an
entity instance can belong to only one subclass.

2. **Completeness Constraint**: Specialization may be total or partial. In a total


specialization, every superclass entity instance must belong to at least one subclass.
In a partial specialization, superclass entities may or may not belong to a subclass.

3. **Attributes and Relationships**: Subclasses inherit attributes and relationships


from the superclass, but they may also have their own specific attributes and
relationships that are not shared with other subclasses.

4. **Specificity**: Each subclass represents a specific subset of the superclass,


typically focusing on a particular aspect or specialization within the broader context
represented by the superclass.

5. **Overlapping Subclasses**: In some cases, subclasses may overlap, meaning an


entity instance can belong to multiple subclasses simultaneously. However, this
scenario is less common in strict specialization.

Generalization:
1. **Inheritance**: Generalization represents the process of combining two or more
subclasses to form a superclass. In other words, it's the reverse of specialization.

2. **Abstraction**: Generalization involves abstracting common attributes and


relationships from multiple subclasses into a single superclass, capturing shared
characteristics among them.

3. **Flexibility**: Generalization increases flexibility by allowing entities to be treated


uniformly at a higher level of abstraction. Queries and operations can be performed
on the superclass, affecting all its subclasses.

4. **Hierarchical Structure**: Generalization often leads to a hierarchical structure in


the ER diagram, where superclass entities are positioned at higher levels, and
subclasses are positioned at lower levels.

5. **Polymorphism**: Generalization enables polymorphic behavior, where


entities of different types can be treated interchangeably at the superclass
level, providing a more generic perspective on the data model.

In summary, specialization and generalization in an ER diagram context involve the


division and combination of entities to represent specific and generalized aspects of
the data model, respectively.

Important Terminologies
These are some important terminologies that are used in terms of relation.
 Attribute:Attributes are the properties that define a relation.
e.g.; ROLL_NO, NAME etc.
 Tuple:Each row in the relation is known as tuple. The above relation
contains 4 tuples, one of which is shown as:
1 RAM DELHI 9455123451 18
 Degree:The number of attributes in the relation is known as degree of the
relation. The STUDENT relation defined above has degree 5.
 Cardinality:The number of tuples in a relation is known as cardinality.
The STUDENTrelation defined above has cardinality 4.
 Column:Column represents the set of values for a particular attribute. The
column ROLL_NO is extracted from relation STUDENT.

SQL, or Structured Query Language, is the foundation for interacting with relational
databases. While it can get complex, the basic structure of an SQL query is actually
quite straightforward. Here's a breakdown of the key components:

1. SELECT Clause: This clause tells the database what specific data you want to
retrieve. You can select individual columns by name, or use an asterisk (*) to select
all columns from a table.
2. FROM Clause: This clause specifies the table(s) that contain the data you're
interested in. You can select data from a single table or join multiple tables together
based on common fields.
3. WHERE Clause (Optional): This clause allows you to filter the results based on
specific conditions. You can use comparison operators (like =, >, <) and logical
operators (AND, OR, NOT) to narrow down the data you retrieve.

Here's an example of a basic SQL query that retrieves all the names (column
"name") from a table called "customers":

SQL
SELECT name
FROM customers;

This is a simple example, but it demonstrates the core structure of SELECT, FROM,
and WHERE clauses. As you get more comfortable with SQL, you can explore
additional functionalities like:

 ORDER BY Clause: Sorts the results based on a specified column.


 GROUP BY Clause: Groups the data based on certain criteria and performs
aggregate functions (like COUNT, SUM, AVG) on the groups.
 JOIN Clauses: Combine data from multiple tables based on relationships
between them.

By understanding these fundamentals, you can start building powerful SQL queries
to extract and manipulate data from your relational databases.

You might also like