0% found this document useful (0 votes)
8 views22 pages

Database Concepts

The document provides an overview of database concepts, including the purpose of databases, data security, and privacy. It explains key terms such as relation, domain, tuple, and various types of keys, as well as data models like network and hierarchical. Additionally, it covers relational algebra operations, including selection, projection, Cartesian product, and SQL joins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views22 pages

Database Concepts

The document provides an overview of database concepts, including the purpose of databases, data security, and privacy. It explains key terms such as relation, domain, tuple, and various types of keys, as well as data models like network and hierarchical. Additionally, it covers relational algebra operations, including selection, projection, Cartesian product, and SQL joins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

DATABASE CONCEPTS

A Database system is basically a


collection of interrelated data stored
together to serve multiple
applications.
PURPOSE OF DATABASE
ü Databases reduce the data redundancy to a
large extent. Duplication of data is known as
Redundancy.
üDatabases can control data inconsistency to
a large extent.
üDatabase facilitate sharing of data.
üDatabase enforce standards.
üDatabase can ensure data security.
üIntegrity can be maintained through
databases.
Data Security : Data
Security refers to protection
of data against accidental or
intentional disclosure to
unauthorized modification or
disclosure
Privacy of Data : Privacy of data
refers to the rights of individuals and
organizations to determine for
themselves when, how and to what
extent information about them is to be
transmitted to others.
DATABASE ABSTRACTION :
Major idea of having a database system is
to provide the users only that much
information that is required by them.

DATABASE INDEPENDENCE:
The ability to modify a scheme definition in
one level without affecting a scheme
definition in the next higher level is called
Data Independence.
Relation : A Relation of a table is data
arranged in rows and columns.

Domain : A Domain is a pool of values


from which the actual values appearing
in a given column are drawn.

Tuple: The rows of tables are generally


referred to as Tuples.

Attribute: The columns of tables are


referred to as attributes.
Degree: The number of attributes in a
relation determine the degree of a
relation.

Cardinality : The number of rows in a


relation is known as Cardinality.

Primary Key: A Primary Key is a set of


one attribute that can uniquely identify
tuples within the relation. eg Rollno
Candidate Key: All attribute combinations inside a
relation that can serve as primary key are
Candidate Keys as they are the candidates for the
primary key position. eg rollno, admno, name
Alternate Key: A candidate key that is not a
primary key is called an Alternate Key.
Candidate key – Primary Key = Alternate Key

Foreign Key: A non-key attribute whose values


are derived from the primary key of some
other table, is known as Foreign key in its
current table. In the eg below ID from
Customers table is the foreign key for
CustomerOrders table. It maybe NULL if it is
not the primary key of another table.
Network Data Model:
The collection of records are connected
to one another by means of links which
means that it is an association between
precisely two records.

Hierarchical Data Model:


The records are organised as trees
rather than graph. It represents
relationship through parent-child
relationships.
The Relational Algebra :
The Relational algebra is a collection of operations on relations.
Each operation takes one or more relations as its operand and
produces its result. The operations defined in relational algebra
include select, project, Cartesian product, union, set difference, set
intersection, natural join, division etc.

The Select Operation: The select operation selects tuples from a


relation that satisfy a given predicate(given condition). The
selection is denoted by greek letter sigma .

The Project Operation : The project operation yields a ‘vertical’


subset of a given relation in contrast to the ‘horizontal’ subset
returned by the select operation. The projection selects specified
attributes in a specified order – the duplicating tuples are
automatically removed.
Projection is denoted by Greek letter pi(π).
Projection, Selection
Projection( 𝜋) means choosing which columns (or expressions) the query
shall return.This operation selects certain required attributes, while
discarding other attributes.

Selection(𝜎) means which rows are to be returned. This operation chooses


the subset of tuples from the relation that satisfies the given condition
mentioned in the syntax of selection.
The Cartesian Product : The Cartesian product is a binary operation and is
denoted by a cross (x). The Cartesian product of two relations A and B is
written as A x B. The Cartesian product yields a new relation which has a
degree(number of attributes) equal to the sum of the degrees of the two
relations operated upon.

The number of tuples (cardinality) of the new relation is the product of


the number of tuples of the two relations operated upon.

The Cartesian product of two relations yields


a relation with all possible combinations of the
tuples of the two relations operated upon.
Cartesian Product of R and S

Table Cardinality Degree

R 5 2

S 4 2

RXS 5*4=20 2+2=4


Union: It produces a third relation that contains tuples
from both the operand relations.
The two tables must have same degrees,
There must be one common attribute In the two tables.
SQL Joins - EQUI JOIN and NATURAL JOIN
Equi join in SQL is a type of Inner Join in which two or more tables are joined by equating the
common column values of the tables. Common columns are columns that have the same name in both
tables.

A natural join is a type of equi join which occurs implicitly by comparing all the same names columns in
both tables. The join result has only one column for each pair of equally named columns. In other
words, the Natural Join helps to join the two tables based on the same attribute name and the
datatypes.

We use Equi Join if we need both tables in the output without missing any column. We use Natural Join
if we need only the unique columns without repetition

SELECT * FROM
Employee
NATURAL JOIN
Department;
SQL Joins
A JOIN clause is used to combine rows from two or more tables, based on
a related column between them.

•(INNER) JOIN: Returns records that have matching values in both tables
•LEFT (OUTER) JOIN: Returns all records from the left table, and the
matched records from the right table
•RIGHT (OUTER) JOIN: Returns all records from the right table, and the
matched records from the left table
•FULL (OUTER) JOIN
Examples of different joins

You might also like