0% found this document useful (0 votes)
2 views23 pages

DBMS ppt5

The document outlines the relational model of databases, describing how data is organized into relations (tables) with rows (tuples) and columns (attributes). It discusses relational algebra operations such as SELECT and PROJECT, which allow users to retrieve and manipulate data, as well as constraints like domain, key, and referential integrity that ensure data consistency. Additionally, it explains the RENAME operation for altering relation and attribute names within queries.

Uploaded by

Subham Garain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

DBMS ppt5

The document outlines the relational model of databases, describing how data is organized into relations (tables) with rows (tuples) and columns (attributes). It discusses relational algebra operations such as SELECT and PROJECT, which allow users to retrieve and manipulate data, as well as constraints like domain, key, and referential integrity that ensure data consistency. Additionally, it explains the RENAME operation for altering relation and attribute names within queries.

Uploaded by

Subham Garain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

DBMS

• The relational model represents the database as a collection of relations. Informally, each relation resembles
a table of values or, to some extent, a flat file of records. It is called a flat file because each record has a
simple linear or flat structure. For example, the database of files that was shown in Figure is similar to the
basic relational model representation.

• When a relation is thought of as a table of values, each row in the table represents a collection of related
data values. A row represents a fact that typically corresponds to a real-world entity or relationship. The
table name and column names are used to help to interpret the meaning of the values in each row.
• In the formal relational model terminology, a row is called a tuple, a column
header is called an attribute, and the table is called a relation. The data type
describing the types of values that can appear in each column is
represented by a domain of possible values.

• The degree (or arity) of a relation is the number of attributes n of its


relation schema.
• A relation of degree seven, which stores information about university
students, would contain seven attributes describing each student. as
follows:
• STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa)
• Relational Model Constraints:-

• Domain Constraints Domain constraints specify that within each tuple, the value of each attribute A must be
an atomic value from the domain.
• Key Constraints and Constraints on NULL Values
• This means that no two tuples can have the same combination of values for all their attributes.
• Another constraint on attributes specifies whether NULL values are or are not permitted. For example, if
every STUDENT tuple must have a valid, non-NULL value for the Name attribute, then Name of STUDENT is
constrained to be NOT NULL.
• Integrity, Referential Integrity, and Foreign Keys
• The entity integrity constraint states that no primary key value can be NULL. This is because the primary key
value is used to identify individual tuples in a relation. Having NULL values for the primary key implies that
we cannot identify some tuples.
• The referential integrity constraint is specified between two relations and is used to maintain the
consistency among tuples in the two relations. Informally, the referential integrity constraint states that a
tuple in one relation that refers to another relation must refer to an existing tuple in that relation. For
example, in Figure the attribute Dno of EMPLOYEE gives the department number for which each employee
works; hence, its value in every EMPLOYEE tuple must match the Dnumber value of some tuple in the
DEPARTMENT relation.
• A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 and it act as the
primary key attributes PK of R2; the attributes FK are said to reference or refer to the relation R2.
Relational algebra
• The basic set of operations for the relational model is the relational
algebra. These operations enable a user to specify basic retrieval
requests as relational algebra expressions. The result of a retrieval is a
new relation, which may have been formed from one or more
relations. The algebra operations thus produce new relations, which
can be further manipulated using operations of the same algebra. A
sequence of relational algebra operations forms a relational algebra
expression, whose result will also be a relation that represents the
result of a database query (or retrieval request).
• The relational algebra is often considered to be an integral part of the relational data
model. Its operations can be divided into two groups. One group includes set
operations from mathematical set theory; these are applicable because each relation is
defined to be a set of tuples in the formal relational model . Set operations include
UNION, INTERSECTION, SET DIFFERENCE, and CARTESIAN PRODUCT (also known as
CROSS PRODUCT).

• The other group consists of operations developed specifically for relational databases—
these include SELECT, PROJECT, and JOIN, among others.

• unary operations that operate on single relations. SELECT and PROJECT


• complex binary operations, which operate on two tables by combining related tuples
(records) based on join conditions. JOIN UNION, INTERSECTION, SET DIFFERENCE, and
CARTESIAN PRODUCT
The SELECT Operation
• The SELECT operation is used to choose a subset of
the tuples from a relation that satisfies a selection
condition. One can consider the SELECT operation
to be a filter that keeps only those tuples that
satisfy a qualifying condition. Alternatively, we can
consider the SELECT operation to restrict the tuples
in a relation to only those tuples that satisfy the
condition.
• SELECT shows tuples or rows.
• For example, to select the EMPLOYEE tuples whose department is 4, or those
whose salary is greater than $30,000, we can individually specify each of
these two conditions with a SELECT operation as follows:
• σDno=4(EMPLOYEE)
• σSalary>30000(EMPLOYEE)
• In general, the SELECT operation is denoted by
• σ<selection condition>(R)
• where the symbol σ (sigma) is used to denote the SELECT operator and the
selection condition is a Boolean expression (condition) specified on the
attributes of relation R.
• Therelation resulting from the SELECT operation has the same attributes as R.
• to select the tuples for all employees who either work in department
4 and make over $25,000 per year, or work in department 5 and make
over $30,000, we can specify the following SELECT operation:
• σ(Dno=4 AND Salary>25000) OR (Dno=5 AND Salary>30000) (EMPLOYEE)
• If the condition evaluates to TRUE, then tuple t is selected. All the selected tuples
appear in the result of the SELECT operation. The Boolean conditions AND, OR, and
NOT have their normal interpretation, as follows:
• ■ (cond1 AND cond2) is TRUE if both (cond1) and (cond2) are TRUE; otherwise, it is
FALSE.
• ■ (cond1 OR cond2) is TRUE if either (cond1) or (cond2) or both are TRUE; otherwise,
it is FALSE.
• ■ (NOT cond) is TRUE if cond is FALSE; otherwise, it is FALSE.

• SELECT operation is commutative; that is,


• σ<cond1>(σ<cond2>(R)) = σ<cond2>(σ<cond1>(R))
• we can always combine a cascade (or sequence) of SELECT operations into a single
SELECT operation with a conjunctive (AND) condition; that is,

• σ<cond1>(σ<cond2>(...(σ<condn>(R)) ...)) = σ<cond1> AND<cond2>


AND...AND <condn>(R).

• σDno=4 AND Salary>25000 (EMPLOYEE)


would correspond to the following SQL query:
• SELECT *FROM EMPLOYEE WHERE Dno=4 AND Salary>25000;
The PROJECT Operation
• The PROJECT operation, on the other hand, selects certain columns from the table and
discards the other columns. If we are interested in only certain attributes of a relation,
we use the PROJECT operation to project the relation over these attributes only.
• If the attribute list includes only nonkey attributes of R, duplicate tuples are likely to
occur. The PROJECT operation removes any duplicate tuples, so the result of the
PROJECT operation is a set of distinct tuples, and hence a valid relation. This is known
as duplicate elimination.

• πLname, Fname, Salary(EMPLOYEE)


• The result of the PROJECT operation has only the attributes specified in
<attribute list> in the same order as they appear in the list. Hence, its
degree is equal to the number of attributes in <attribute list>.
• π<list1> (π<list2>(R)) = π<list1>(R)
• as long as <list2> contains the attributes in <list1>; otherwise, the left-
hand side is an incorrect expression.
• In SQL, the PROJECT attribute list is specified in the SELECT clause of a
query. For example, the following operation:
• πLname, Salary(EMPLOYEE)
• would correspond to the following SQL query:
• SELECT DISTINCT Lname, Salary FROM EMPLOYEE
Sequences of Operations and the
RENAME Operation
• πFname, Lname, Salary(σDno=5(EMPLOYEE))
• TEMP ← σDno=5(EMPLOYEE)
• R(First_name, Last_name, Salary) ← πFname, Lname, Salary(TEMP)
• We can also define a formal RENAME operation—which can rename
either the relation name or the attribute names, or both—as a unary
operator. The general RENAME operation when applied to a relation R
of degree n is denoted by any of the following three forms:
• ρS(B1, B2, ..., Bn)(R) or ρS(R) or ρ(B1, B2, ..., Bn)(R)
• where the symbol ρ (rho) is used to denote the RENAME operator, S is
the new relation name, and B1, B2, ..., Bn are the new attribute
names. The first expression renames both the relation and its
attributes, the second renames the relation only, and the third
renames the attributes only. If the attributes of R are (A1, A2, ..., An)
in that order, then each Ai is renamed as Bi.
• In SQL, a single query typically represents a complex relational algebra expression.
Renaming in SQL is accomplished by aliasing using AS, as in the following example:
• SELECT E.Fname AS First_name, E.Lname AS Last_name, E.Salary AS Salary FROM
EMPLOYEE AS E WHERE E.Dno=5,

You might also like