Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views8 pages

Trigger - Assertion - Relational Algebra - Relational Calculus

Uploaded by

mishraji9333
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)
16 views8 pages

Trigger - Assertion - Relational Algebra - Relational Calculus

Uploaded by

mishraji9333
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/ 8

TRIGGER

A database trigger is procedural code that is automatically executed in


response to certain events on a particular table or view in a database. The
trigger is mostly used for maintaining the integrity of the information on the
database.
The four main types of triggers are:
1. Row Level Trigger: This gets executed before or after any column value of a
row changes
2. Column Level Trigger: This gets executed before or after the specified
column changes
3. For Each Row Type: This trigger gets executed once for each row of the
result set affected by an insert/update/delete
4. For Each Statement Type: This trigger gets executed only once for the entire
result set, but also fires each time the statement is executed.

Syntax

create trigger [trigger_name]

[before | after]

{insert | update | delete}

[OF column_name]

on [table_name]

[for each row]

[trigger_body]
ASSERTION

An assertion is a statement that ensures that certain conditions are always


enforced in the database .It is a named statement that defines a condition that
must be true for the data in the database. If the condition is not met, the
assertion will fail and the database will generate an error.

It enforces complex database constraints that cannot be enforced using the


standard constraint types.Not all DBMS support SQL Assertions.

syntax

CREATE ASSERTION assertion_name

CHECK (condition);

Example :

Create Assertion order_total

check (( select SUM(Amount) from Orders) <5000);

Relational Algebra

Relational Algebra is a procedural language used for manipulating relations.


The relational model gives the structure for relations so that data can be
stored in that format but relational algebra enables us to retrieve information
from relations. Some advanced SQL queries requires explicit relational algebra
operations, most commonly outer join.

Relations are seen as sets of tuples, which means that no duplicates are
allowed. SQL is declarative, which means that you tell the DBMS what you
want.
It uses operators to perform queries. An operator can be either unary or
binary.

Relational Algebra Operations :

1)Select Operation (σ)

It selects tuples that satisfy the given predicate from a relation.It is denoted by
sigma (σ).

Notation: σ p(r)

where

σ =selection prediction

r = relation

p =propositional logic formula which may use connectors like: AND OR and
NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.

Example- σ subject=”DBMS”(BOOKS)

Output − Selects tuples from relation books where subject is 'DBMS'.

2)Project Operation(π)

This operation shows the list of those attributes that we wish to appear in the
result. Rest of the attributes are eliminated from the table.It is denoted by pi
(π).

Notation: π A1, A2, An (r)

where

A1, A2, An is used as an attribute name of relation r.

Example - π NAME, CITY (CUSTOMER)


Output- shows the list of attributes NAME & CITY from relation CUSTOMER

3)Union Operation (∪)

Suppose there are two relations R and S. The union operation contains all the
tuples that are either in R or S or both in R & S.It eliminates the duplicate
tuples. It is denoted by ∪.Union can only be performed on two relations that
have the same schema.

Notation : R U S

Example - π CUSTOMER_NAME (BORROW) ∪ π CUSTOMER_NAME


(DEPOSITOR)

5)Set Intersection(∩)

The Intersection of relation A and relation B is a new relation containing all of


the tuples that are contained in both relation A and relation B. Intersection can
only be performed on two relations that have the same schema. The symbol
for intersection is ∩.

Notation - A ∩ B

6)Set Difference(-)

Suppose there are two relations R and S. The set intersection operation
contains all tuples that are in R but not in S.It is denoted by intersection minus
(-).

Notation - R - S
7)Cartesian product

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.It is denoted by X.

Notation: R X S

If R has ‘n’ tuples and S has ‘m’ tuples then R X S will have “ n*m “ tuples.

8)Rename Operation

The rename operation is used to rename the output relation. It is denoted by


rho (ρ).

Example: We can use the rename operator to rename STUDENT relation to


STUDENT1.

ρ(STUDENT1, STUDENT)

9) Join Operation

It combines the relation R1 and R2 with respect to a condition. It is denoted by


⋈.

Join operation = select operation + cartesian product operation

Types of join:

a)Theta join

If we join R1 and R2 other than the equal to condition then it is called theta
join/ non-equi join.

Example: R1.regno>R2.regno.

b)Equi/Natural join
If we join R1 and R2 on equal condition then it is called natural join or equi
join.

Example: R1.regno=R2.regno

c)Outer join

It is further classified into following types −

● Left outer join.


● Right outer join.
● Full outer join.
Relational Calculus

Relational calculus is a non-procedural query language. It uses mathematical


predicate calculus. It specifies what data is required from the database, rather
than how to retrieve it.

There are two types of relational calculus -

1) Tuple Relational Calculus (TRC)

It is a non-procedural query language which is based on finding a number of


tuple variables also known as range variable for which predicate holds true. It
describes the desired information without giving a specific procedure for
obtaining that information. The tuple relational calculus is specified to select
the tuples in a relation.

Notation : {T | P (T)} or {T | Condition (T)}

where

T is the resulting tuples

P(T) is the condition used to fetch T.

2) Domain Relational Calculus(DRC).

Domain Relational Calculus uses domain Variables to get the column values
required from the database based on the predicate expression or condition.

Notation: {<a1,a2,a3,.....an> | P(a1,a2,a3,.....an)}

where ,

a1,a2,…an = are the attributes of the relation


P is the condition.

You might also like