Unit-II
Unit-II
Relational data Model and Language: Relational data model concepts, integrity constraints, entity integrity,
referential integrity, Keys constraints, Domain constraints, relational algebra, relational calculus, tuple and domain
calculus.
Introduction on SQL: Characteristics of SQL, advantage of SQL. SQl data type and literals. Types of SQL commands.
SQL operators and their procedure. Tables, views and indexes. Queries and sub queries. Aggregate functions. Insert,
update and delete operations, Joins, Unions, Intersection, Minus, Cursors, Triggers, Procedures in SQL/PL SQL
Example: If
Attribute Types
Relation Schema
Example:
Example:
customer (Customer_schema)
Relation Instance
Database
A database consists of multiple relations
Information about an enterprise is broken up into parts, with each relation storing one part of the
information
results in
o repetition of information
Keys
Superkey
Let K Í R
K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R)
o by “possible r ” we mean a relation r that could exist in the enterprise we are modeling.
Candidate Key
Primary Key
a candidate key chosen as the principal means of identifying tuples within a relation
o Should choose an attribute whose value never, or very rarely, changes.
o E.g. email address is unique, but may change
Foreign Keys
A relation schema may have an attribute that corresponds to the primary key of another relation. The
attribute is called a foreign key.
o E.g. customer_name and account_number attributes of depositor are foreign keys to customer and
account respectively.
o Only values occurring in the primary key attribute of the referenced relation may occur in the
foreign key attribute of the referencing relation.
Query Languages
Relational Algebra
The relational algebra defines a set of operations on relations, paralleling the usual algebraic operations such
as addition, subtraction or multiplication, which operate on numbers.
4|Page PRAMOD KUMAR (ASST.PROF.)
Just as algebraic operations on numbers take one or more numbers as input and return a number as output,
the relational algebra operations typically take one or two relations as input and return a relation as output.
It is procedural language
Six basic operators
o select: (Return rows of the input relation that satisfy the predicate.)
o project: π (Output specified attributes from all rows of the input relation. Remove duplicate tuples
from the output.)
o union: U ( Output the union of tuples from the two input relations.)
o set difference: –
o Cartesian product: x (Output all pairs of rows from the two input relations (regardless of whether or
not they have the same values on common attributes)
o rename:
The operators take one or two relations as inputs and produce a new relation as a result.
Relation r:
For r U s to be valid.
o r, s must have the same arity (same number of attributes)
Notation: r ÷s
Suited to queries that include the phrase “for all”.
Let r and s be relations on schemas R and S respectively
where
R = (A1, …, Am , B1, …, Bn )
S = (B1, …, Bn)
The result of r ¸ s is a relation on schema
R – S = (A1, …, Am)