Professional Documents
Culture Documents
The Project
The selection operation operation is also
Other is also known as known as vertical
1. Names horizontal partitioning. partitioning.
The projection
operation is
The selection operation performed after
is performed before selection (if they
Which used projection (if they are to are to be used
4. first be used together). together).
Project operator is
Operator Select operator is used used in Projection
5. Used in Selection Operation. Operation.
A----Relational algebra is a query language that processes one or more relations to define
another relation.
The basic operation of relational algebra are as follows;
1.Unary operations
Selection, Projection
Operations which involve only one relation are called unary operations.
2.Binary operations:
Operations which involve pairs of relations are called binary operations.
Examples:
Union, Difference, Cartesian product
A-----On modeling the design of the relational database we can put some
restrictions like what values are allowed to be inserted in the relation, what kind
of modifications and deletions are allowed in the relation. These are the
restrictions we impose on the relational database.
In models like ER models, we did not have such features.
Constraints in the databases can be categorized into 3 main categories:
1. Constraints that are applied in the data model is called Implicit
constraints.
2. Constraints that are directly applied in the schemas of the data model,
by specifying them in the DDL(Data Definition Language). These are
called as schema-based constraints or Explicit constraints.
3. Constraints that cannot be directly applied in the schemas of the data
model. We call these Application based or semantic constraints.
So here we will deal with Implicit constraints.
Mainly Constraints on the relational database are of 4 types:
1. Domain constraints
2. Key constraints
3. Entity Integrity constraints
4. Referential integrity constraints
Let discuss each of the above constraints in detail.
1. Domain constraints :
1. Every domain must contain atomic values(smallest indivisible units) it
means composite and multi-valued attributes are not allowed.
2. We perform datatype check here, which means when we assign a data
type to a column we limit the values that it can contain. Eg. If we assign
the datatype of attribute age as int, we cant give it values other then int
datatype.
Example:
Explanation:
In the above relation, Name is a composite attribute and Phone is a multi-values
attribute, so it is violating domain constraint.
2. Key Constraints or Uniqueness Constraints :
1. These are called uniqueness constraints since it ensures that every
tuple in the relation should be unique.
2. A relation can have multiple keys or candidate keys(minimal
superkey), out of which we choose one of the keys as primary key, we
don’t have any restriction on choosing the primary key out of candidate
keys, but it is suggested to go with the candidate key with less number
of attributes.
3. Null values are not allowed in the primary key, hence Not Null
constraint is also a part of key constraint.
Example:
Explanation:
In the above table, EID is the primary key, and first and the last tuple has the
same value in EID ie 01, so it is violating the key constraint.
3. Entity Integrity Constraints :
1. Entity Integrity constraints says that no primary key can take NULL
value, since using primary key we identify each tuple uniquely in a
relation.
Example:
Explanation:
In the above relation, EID is made primary key, and the primary key cant take
NULL values but in the third tuple, the primary key is null, so it is a violating
Entity Integrity constraints.
4. Referential Integrity Constraints :
1. The Referential integrity constraints is specified between two relations
or tables and used to maintain the consistency among the tuples in two
relations.
2. This constraint is enforced through foreign key, when an attribute in
the foreign key of relation R1 have the same domain(s) as the primary
key of relation R2, then the foreign key of R1 is said to reference or
refer to the primary key of relation R2.
3. The values of the foreign key in a tuple of relation R1 can either take
the values of the primary key for some tuple in relation R2, or can take
NULL values, but can’t be empty.
Example:
Explanation:
In the above, DNO of the first relation is the foreign key, and DNO in the second
relation is the primary key. DNO = 22 in the foreign key of the first table is not
allowed since DNO = 22
is not defined in the primary key of the second relation. Therefore, Referential
integrity constraints is violated here
Like20
A=====Data Model gives us an idea that how the final system will
look like after its complete implementation. It defines the data
elements and the relationships between the data elements. Data
Models are used to show how data is stored, connected, accessed
and updated in the database management system. Here, we use a
set of symbols and text to represent the information so that
members of the organisation can communicate and understand it
Data Models
Data Model is the modeling of the data description, data semantics, and consistency
constraints of the data. It provides the conceptual tools for describing the design of a
database at each level of data abstraction. Therefore, there are following four data
models used for understanding the structure of the database:
1) Relational Data Model: This type of model designs the data in the form of rows
and columns within a table. Thus, a relational model uses tables for representing data
and in-between relationships. Tables are also called relations. This model was initially
described by Edgar F. Codd, in 1969. The relational data model is the widely used
model which is primarily used by commercial data processing applications.
4) Semistructured Data Model: This type of data model is different from the other
three data models (explained above). The semistructured data model allows the data
specifications at places where the individual data items of the same type may have
different attributes sets. The Extensible Markup Language, also known as XML, is
widely used for representing the semistructured data. Although XML was initially
designed for including the markup information to the text document, it gains
importance because of its application in the exchange of data.
A======elational Algebra
Relational algebra is a procedural query language. It gives a step by step process to
obtain the result of the query. It uses operators to perform queries.
1. Select Operation:
o The select operation selects tuples that satisfy a given predicate.
o It is denoted by sigma (σ).
1. Notation: σ p(r)
Where:
Input:
1. σ BRANCH_NAME="perryride" (LOAN)
Output:
ADVERTISEMENT BY ADRECOVER
Where
Input:
Output:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
3. Union Operation:
o Suppose there are two tuples R and S. The union operation contains all the tuples that
are either in R or S or both in R & S.
o It eliminates the duplicate tuples. It is denoted by ∪.
1. Notation: R ∪ S
Example:
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
Input:
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
4. Set Intersection:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.
o It is denoted by intersection ∩.
1. Notation: R ∩ S
Input:
Output:
CUSTOMER_NAME
Smith
Jones
5. Set Difference:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in R but not in S.
o It is denoted by intersection minus (-).
1. Notation: R - S
Input:
Output:
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
6. Cartesian product
o The Cartesian product is used to combine each row in one table with each row in the
other table. It is also known as a cross product.
o It is denoted by X.
1. Notation: E X D
Example:
EMPLOYEE
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
Input:
1. EMPLOYEE X DEPARTMENT
Output:
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
7. Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ).
1. ρ(STUDENT1, STUDENT)
Generalization
• It works using bottom-up approach.
• It can be defined as a process where grouping are created from multiple entity
sets.
• It takes the union of two or more lower-level entity sets, and produces a higher-
level entity set.
• Some of the common features are obtained in the resultant higher-level entity
set.
• The differences and similarities between the entities that need to be in union
operation are ignored.
Example:
Pigeon, house sparrow, crow and dove can all be generalized as Birds −
Specialization
• It uses a top-down approach.
• It takes a subset of higher level entity, and forms a lower-level entity set.
Example
A person has name, date of birth, gender, etc. These properties are common in all
persons, human beings. But in a company, persons can be identified as employee,
employer, customer, or vendor, based on what role they play in the company.
A======Mapping Constraints
o A mapping constraint is a data constraint that expresses the number of entities to
which another entity can be related via a relationship set.
o It is most useful in describing the relationship sets that involve more than two entity
sets.
o For binary relationship set R on an entity set A and B, there are four possible mapping
cardinalities. These are as follows:
0. One to one (1:1)
1. One to many (1:M)
2. Many to one (M:1)
3. Many to many (M:M)
One-to-one
In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and
an entity in E2 is associated with at most one entity in E1.
One-to-many
In one-to-many mapping, an entity in E1 is associated with any number of entities in
E2, and an entity in E2 is associated with at most one entity in E1.
Many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one entity in E2,
and an entity in E2 is associated with any number of entities in E1.
ADVERTISEMENT BY ADRECOVER
Many-to-many
In many-to-many mapping, an entity in E1 is associated with any number of entities in
E2, and an entity in E2 is associated with any number of entities in E1.
A====
DML Precompiler
All the DBMS have two basic sets of Languages - Data Definition Language (DDL) that
have the set of commands needed to define the format of the data that is being
stored and Data Manipulation Language (DML) which tells the set of commands that
modify, process data to make user definable output. The DML statements can as well
be written in an application program. The DML precompiler changes DML statements
(such as SELECT...FROM in Structured Query Language (SQL) covered in Block 2)
embedded in an application program to normal procedural calls in the host language.
The precompiler relate with the query processor in order to produce the appropriate
code.
A====
The Database Management System (DBMS) is defined as a software system that
allows the user to define, create and maintain the database and provide control access
to the data.
It is a collection of programs used for managing data and simultaneously it supports
different types of users to create, manage, retrieve, update and store information.
Advantages of DBMS
The advantages of the DBMS are explained below −
• Avoidance of inconsistency.
DBMS controls data redundancy and also controls data consistency. Data consistency
is nothing but if you want to update data in any files then all the files should not be
updated again.
In DBMS, data is stored in a single database so data becomes more consistent in
comparison to file processing systems.
• Shared data
Data can be shared between authorized users of the database in DBMS. All the users
have their own right to access the database. Admin has complete access to the
database. He has a right to assign users to access the database.
• Enforcement of standards
As DBMS have central control of the database. So, a DBA can ensure that all the
applications follow some standards such as format of data, document standards etc.
These standards help in data migrations or in interchanging the data.
• Any unauthorized access is restricted
Unauthorized persons are not allowed to access the database because of security
credentials.
• Complexity
The provision of the functionality that is expected of a good DBMS makes the DBMS
an extremely complex piece of software. Database designers, developers, database
administrators and end-users must understand this functionality to take full advantage
of it.
Failure to understand the system can lead to bad design decisions, which leads to a
serious consequence for an organization.
• Size
The functionality of DBMS makes use of a large piece of software which occupies
megabytes of disk space.
• Performance
Performance may not run as fast as desired.
ADVERTISEMENT BY ADRECOVER
1. Internal Level
o The internal level has an internal schema which describes the physical storage structure
of the database.
o The internal schema is also known as a physical schema.
o It uses the physical data model. It is used to define that how the data will be stored in
a block.
o The physical level is used to describe complex low-level data structures in detail.
The internal level is generally is concerned with the following activities:
2. Conceptual Level
o The conceptual schema describes the design of a database at the conceptual level.
Conceptual level is also known as logical level.
o The conceptual schema describes the structure of the whole database.
o The conceptual level describes what data are to be stored in the database and also
describes what relationship exists among those data.
o In the conceptual level, internal details such as an implementation of the data structure
are hidden.
o Programmers and database administrators work at this level.
3. External Level
o At the external level, a database contains several schemas that sometimes called as
subschema. The subschema is used to describe the different view of the database.
o An external schema is also known as view schema.
o Each view schema describes the database part that a particular user group is interested
and hides the remaining database from that user group.
o The view schema describes the end user interaction with database systems.
The Conceptual/ Internal Mapping lies between the conceptual level and the internal
level. Its role is to define the correspondence between the records and fields of the
conceptual level and files and data structures of the internal level.
The external/Conceptual Mapping lies between the external level and the Conceptual
level. Its role is to define the correspondence between a particular external and the
conceptual view.
A=====Recursive Relationships in ER
diagrams
• Difficulty Level : Medium
• Last Updated : 10 Jun, 2021
Prerequisite – ER Model
A relationship between two entities of a similar entity type is called
a recursive relationship. Here the same entity type participates more than once
in a relationship type with a different role for each instance. In other words, a
relationship has always been between occurrences in two different entities.
However, the same entity can participate in the relationship. This is termed
a recursive relationship.
Example –
Let us suppose that we have an employee table. A manager supervises a
subordinate. Every employee can have a supervisor except the CEO and there can
be at most one boss for each employee. One employee may be the boss of more
than one employee. Let’s suppose that REPORTS_TO is a recursive relationship
on the Employee entity type where each Employee plays two roles.
1. Supervisor
2. Subordinate
Supervisors and subordinates are called “Role Names”. Here the degree of the
REPORTS_TO relationship is 1 i.e. a unary relationship.
• Potential bugs in your SQL due to not being aware of NULL behavior in
operators. Most SQLs will happily allow you to write “mycol = NULL”,
but that always evaluates to NULL, which is effectively FALSE in most
implementations. (Most hand-coded SQL avoids this rookie mistake, but
I’ve seen this in program-generated SQL many times.)
• Exposure to weird, inconsistent NULL semantics in SQL, particularly
when it comes to operations that involve ordering and grouping. In
practice, most people can live with these, but the behavior can be
different across db vendors.
• Many database storage engines make storage optimizations if they
know you don’t have NULLs in a column. This *may* make access
slightly slower if you have a lot of NULLs.