Relational DBMS
 Edgar F. Codd at IBM invented the relational database
in 1970. Called Father of RDBMS.
 The main elements of RDBMS are based on Codd’s 13
rules for a relational system.
 Tables (or relations) are related to each other by
sharing common characteristics
RDBMS
A database management system that stores data in the
form of related tables is called Relational Database
Management System.
The goal of RDBMS is to make data easy to store &
retrieve
Relational databases help solve problems as they are
designed to create tables & then combine the
information in interesting ways to create valid
information.
RDBMS
Typical RDBMS include
Microsoft Access
Microsoft SQL Server
Sybase (The forerunner of Microsoft SQL Server)
IBM DB2
Oracle
Ingres
MySQL
Postgresql etc
RDBMS
Relation Instance:- snapshot of DB
Example:
Schema :- Logical design of DB.
Example:
Account-schema = (account-number, branch-name,
balance)
Branch-schema = (branch-name, branch-city, assets)
Customer-schema = (customer-name, customer-street,
customer-city)
RDBMS
Schema Diagram
Translation ER Model to Relational
Model
Translation ER Model to Relational
Model
Integrity Constraint
An integrity constraint (IC) is a condition specified on
a database schema and restricts the data that can be
stored in an instance of the database.
If a database instance satisfies all the integrity
constraints specifies on the database schema, it is
a legal instance.
A DBMS permits only legal instances to be stored in the
database.
Integrity Constraint
Domain Constraints:
A relation schema specifies the domain of each field in
the relation instance. These domain constraints in the
schema specify the condition that each instance of the
relation has to satisfy.
Example:
create domain Dollars numeric(12,2)
create domain Pounds numeric(12,2)
define the domains Dollars and Pounds to be decimal
numbers with a total of 12 digits, two of which are
placed after the decimal point.
Integrity Constraint
Referential Integrity:
ensure that a value that appears in one relation for a
given set of attributes also appears for a certain set of
attributes in another relation.
Example: SQL
branch-name char(15) references branch
Key Constraints
Super Key:
An attribute, or set of attributes, that uniquely identifies a
tuple within a relation.
However, a super key may contain additional attributes that
are not necessary for a unique identification.
Candidate Key:
A super key such that no proper subset is a super key within
the relation. There are two parts of the candidate key
definition:
i. Two distinct tuples in a legal instance cannot have identical
values in all the fields of a key.
ii. No subset of the set of fields in a candidate key is a unique
identifier for a tuple.
Key Constraints
Primary Key:
The candidate key that is selected to identify tuples
uniquely within the relation.
The candidate keys that are not selected as the primary
key are called as alternate keys.
Features of the primary key:
1. Primary key will not allow duplicate values.
2.Primary key will not allow null values.
3. Only one primary key is allowed per table.
Key Constraints
Foreign Key:
Foreign keys represent the relationships between tables.
A foreign key is a column (or a group of columns)
whose values are derived from the primary key of some
other table.
Features of foreign key:
1. Records cannot be inserted into a detail table if
corresponding records in the master table do not exist.
2. Records of the master table cannot be deleted or
updated if corresponding records in the detail table
actually exist.
Integrity Constraint
Assertions:
An assertion is a predicate expressing a condition that we
wish the database always to satisfy.
create assertion <assertion-name> check <predicate>
Example :
create assertion sum-constraint check
(not exists (select * from branch
where (select sum(amount) from loan
where loan.branch-name = branch.branch-name)
>= (select sum(balance) from account
where account.branch-name = branch.branch-name)))
Integrity Constraint
Triggers:
A trigger is a statement that the system executes
automatically as a side effect of a modification to the
database.
To design a trigger mechanism, we must meet two
requirements:
1. Specify when a trigger is to be executed. This is broken
up into an event that causes the trigger to be checked
and a condition that must be satisfied for trigger
execution to proceed.
2. Specify the actions to be taken when the trigger
executes.
Integrity Constraint
Triggers:
Example: define a trigger that replaces the blank value
in a phone number field of an inserted tuple by the
null value.
create trigger setnull-trigger before update on r
referencing new row as nrow for each row when
nrow.phone-number = ’ ’ set nrow.phone-number = null
Relational Algebra
Fundamental Operations
Unary Operation
 Select
 Project
 Rename
Binary Operations
 Union
 Set different
 Cartesian product
Relational Algebra
Select (σ) :
(a) Example: select those tuples of the loan relation
where the branch is “Perryridge,”
σbranch-name =“Perryridge” (loan)
(b) Example: find those tuples pertaining to loans of
more than $1200 made by the Perryridge branch
σbranch-name =“Perryridge”∧ amount>1200 (loan)
Relational Algebra
Project(Π)
Example: list all loan numbers and the amount of the
loan as
Πloan-number, amount(loan)
Union(∪)
Example: find the names of all bank customers who hav
either an account or a loan or both.
Πcustomer-name (borrower ) ∪ Πcustomer-name (depositor)
borrower : Customers with a loan in the bank
Relational Algebra
Set Difference (-)
Example: find all customers of the bank who have an account
but not a loan
Πcustomer-name (depositor) − Πcustomer-name (borrower )
Cartesian-Product (X)
Example: find the names of all customers who have a loan at
the Perryridge branch.
3. Πcustomer-name (σborrower .loan-number =loan.loan-number
(σbranch-name =“Perryridge” (borrower × loan)))
Relational Algebra
Rename (ρ)
relational-algebra expression E,
ρ x (E)
returns the result of expression E under the name x.
Additional operations are:
• Set intersection
• Assignment
• Natural join
Relational Calculus
Tuple Relational Calculus
A query in the tuple relational calculus is expressed as
{t | P(t)}
the set of all tuples t such that predicate P is true for t.
Domain Relational Calculus
An expression in the domain relational calculus is of the form
{< x1, x2, . . . , xn > | P(x1, x2, . . . , xn)}
where x1, x2, . . . , xn represent domain variables. P represents a
formula composed of atoms, as was the case in the tuple
relational calculus.

Database : Relational Data Model

  • 2.
    Relational DBMS  EdgarF. Codd at IBM invented the relational database in 1970. Called Father of RDBMS.  The main elements of RDBMS are based on Codd’s 13 rules for a relational system.  Tables (or relations) are related to each other by sharing common characteristics
  • 3.
    RDBMS A database managementsystem that stores data in the form of related tables is called Relational Database Management System. The goal of RDBMS is to make data easy to store & retrieve Relational databases help solve problems as they are designed to create tables & then combine the information in interesting ways to create valid information.
  • 4.
    RDBMS Typical RDBMS include MicrosoftAccess Microsoft SQL Server Sybase (The forerunner of Microsoft SQL Server) IBM DB2 Oracle Ingres MySQL Postgresql etc
  • 5.
    RDBMS Relation Instance:- snapshotof DB Example: Schema :- Logical design of DB. Example: Account-schema = (account-number, branch-name, balance) Branch-schema = (branch-name, branch-city, assets) Customer-schema = (customer-name, customer-street, customer-city)
  • 6.
  • 7.
    Translation ER Modelto Relational Model
  • 8.
    Translation ER Modelto Relational Model
  • 10.
    Integrity Constraint An integrityconstraint (IC) is a condition specified on a database schema and restricts the data that can be stored in an instance of the database. If a database instance satisfies all the integrity constraints specifies on the database schema, it is a legal instance. A DBMS permits only legal instances to be stored in the database.
  • 11.
    Integrity Constraint Domain Constraints: Arelation schema specifies the domain of each field in the relation instance. These domain constraints in the schema specify the condition that each instance of the relation has to satisfy. Example: create domain Dollars numeric(12,2) create domain Pounds numeric(12,2) define the domains Dollars and Pounds to be decimal numbers with a total of 12 digits, two of which are placed after the decimal point.
  • 12.
    Integrity Constraint Referential Integrity: ensurethat a value that appears in one relation for a given set of attributes also appears for a certain set of attributes in another relation. Example: SQL branch-name char(15) references branch
  • 13.
    Key Constraints Super Key: Anattribute, or set of attributes, that uniquely identifies a tuple within a relation. However, a super key may contain additional attributes that are not necessary for a unique identification. Candidate Key: A super key such that no proper subset is a super key within the relation. There are two parts of the candidate key definition: i. Two distinct tuples in a legal instance cannot have identical values in all the fields of a key. ii. No subset of the set of fields in a candidate key is a unique identifier for a tuple.
  • 14.
    Key Constraints Primary Key: Thecandidate key that is selected to identify tuples uniquely within the relation. The candidate keys that are not selected as the primary key are called as alternate keys. Features of the primary key: 1. Primary key will not allow duplicate values. 2.Primary key will not allow null values. 3. Only one primary key is allowed per table.
  • 15.
    Key Constraints Foreign Key: Foreignkeys represent the relationships between tables. A foreign key is a column (or a group of columns) whose values are derived from the primary key of some other table. Features of foreign key: 1. Records cannot be inserted into a detail table if corresponding records in the master table do not exist. 2. Records of the master table cannot be deleted or updated if corresponding records in the detail table actually exist.
  • 16.
    Integrity Constraint Assertions: An assertionis a predicate expressing a condition that we wish the database always to satisfy. create assertion <assertion-name> check <predicate> Example : create assertion sum-constraint check (not exists (select * from branch where (select sum(amount) from loan where loan.branch-name = branch.branch-name) >= (select sum(balance) from account where account.branch-name = branch.branch-name)))
  • 17.
    Integrity Constraint Triggers: A triggeris a statement that the system executes automatically as a side effect of a modification to the database. To design a trigger mechanism, we must meet two requirements: 1. Specify when a trigger is to be executed. This is broken up into an event that causes the trigger to be checked and a condition that must be satisfied for trigger execution to proceed. 2. Specify the actions to be taken when the trigger executes.
  • 18.
    Integrity Constraint Triggers: Example: definea trigger that replaces the blank value in a phone number field of an inserted tuple by the null value. create trigger setnull-trigger before update on r referencing new row as nrow for each row when nrow.phone-number = ’ ’ set nrow.phone-number = null
  • 20.
    Relational Algebra Fundamental Operations UnaryOperation  Select  Project  Rename Binary Operations  Union  Set different  Cartesian product
  • 21.
    Relational Algebra Select (σ): (a) Example: select those tuples of the loan relation where the branch is “Perryridge,” σbranch-name =“Perryridge” (loan) (b) Example: find those tuples pertaining to loans of more than $1200 made by the Perryridge branch σbranch-name =“Perryridge”∧ amount>1200 (loan)
  • 22.
    Relational Algebra Project(Π) Example: listall loan numbers and the amount of the loan as Πloan-number, amount(loan) Union(∪) Example: find the names of all bank customers who hav either an account or a loan or both. Πcustomer-name (borrower ) ∪ Πcustomer-name (depositor) borrower : Customers with a loan in the bank
  • 23.
    Relational Algebra Set Difference(-) Example: find all customers of the bank who have an account but not a loan Πcustomer-name (depositor) − Πcustomer-name (borrower ) Cartesian-Product (X) Example: find the names of all customers who have a loan at the Perryridge branch. 3. Πcustomer-name (σborrower .loan-number =loan.loan-number (σbranch-name =“Perryridge” (borrower × loan)))
  • 24.
    Relational Algebra Rename (ρ) relational-algebraexpression E, ρ x (E) returns the result of expression E under the name x. Additional operations are: • Set intersection • Assignment • Natural join
  • 25.
    Relational Calculus Tuple RelationalCalculus A query in the tuple relational calculus is expressed as {t | P(t)} the set of all tuples t such that predicate P is true for t. Domain Relational Calculus An expression in the domain relational calculus is of the form {< x1, x2, . . . , xn > | P(x1, x2, . . . , xn)} where x1, x2, . . . , xn represent domain variables. P represents a formula composed of atoms, as was the case in the tuple relational calculus.

Editor's Notes

  • #6 relation schema corresponds to the programming-language notion of type definition. relation instance corresponds to the programming language notion of a value of a variable.
  • #7 A database schema, along with primary key and foreign key dependencies, can be depicted pictorially by schema diagrams. E-R diagrams do not show foreign key attributes explicitly, whereas schema diagrams show them explicity.
  • #8 Mapping Entity
  • #9 Mapping Relation
  • #12 Domain definitions can be physical & Logical. Such constraints may also prohibit the use of null values for particular attributes. Thus, the domain of a field is essentially the type of that field. Values of one domain can be cast (that is, converted) to another domain. Example : If the attribute A or relation r is of type Dollars, we can convert it to Pounds by writing cast r.A as Pounds
  • #13 By default, a foreign key references the primary key attributes of the referenced table. SQL also supports a version of the references clause where a list of attributes of the referenced relation can be specified explicitly. The specified list of attributes must be declared as a candidate key of the referenced relation.
  • #14 (k1,k2,k3,k4) – superkey –unique identifier for tuple k1 – primary key k2, k3 – candidate key also alternate key K1,k2,k3 – not candiate key
  • #16 The table in which foreign key is defined is called a Foreign table or Details table. The table that defines the primary key and is referenced by the foreign key is called the Primary table or Master table.
  • #17 Domain constraints and referential-integrity constraints are special forms of assertions. When an assertion is created, the system tests it for validity. If the assertion is valid, then any future modification to the database is allowed only if it does not cause that assertion to be violated.
  • #18 The above model of triggers is referred to as the event-condition-action model for triggers.
  • #19 Trigger limited use: For example, suppose an insert trigger on a relation has an action that causes another (new) insert on the same relation. The insert action then triggers yet another insert action, and so on ad infinitum. Database systems typically limit the length of such chains of triggers (for example to 16 or 32), and consider longer chains of triggering an error.
  • #21 The relational algebra is a procedural query language. It consists of a set of operations that take one or two relations as input and produce a new relation as their result.
  • #22 In general, we allow comparisons using =, =, <, ≤, >, ≥ in the selection predicate. Furthermore, we can combine several predicates into a larger predicate by using the connectives and (∧), or (∨), and not (¬). Exercise: find all customers who have the same name as their loan officer, we can write σcustomer-name =banker-name(loan-officer)
  • #23 Since relations are sets, duplicate values are eliminated Composition of Relational Operations Example : “Find those customers who live in Harrison.” Πcustomer-name (σcustomer-city =“Harrison” (customer))
  • #24 Cartesian-Product Example We need the information in both the loan relation and the borrower relation to do so. Cartesian-product operation associates every tuple of loan with every tuple of borrower, 1. σbranch-name =“Perryridge”(borrower × loan) 2. σborrower .loan-number =loan.loan-number (σbranch-name =“Perryridge”(borrower × loan))
  • #25 Rename Operation Excellent Example Further reading from korth
  • #26 The tuple relational calculus, by contrast, is a nonprocedural query language. Following our earlier notation, we use t[A] to denote the value of tuple t on attribute A, andwe use t ∈ r to denote that tuple t is in relation r.