0% found this document useful (0 votes)
38 views

Unit 2 Structure of Rdbms

The document discusses the key concepts of relational database management systems (RDBMS). It defines RDBMS and describes its main components - relations, attributes, domains, tuples, and keys. It explains the concepts of entity integrity and referential integrity enforced through primary keys and foreign keys. Primary keys uniquely identify each tuple in a relation while foreign keys link two relations through their primary keys.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Unit 2 Structure of Rdbms

The document discusses the key concepts of relational database management systems (RDBMS). It defines RDBMS and describes its main components - relations, attributes, domains, tuples, and keys. It explains the concepts of entity integrity and referential integrity enforced through primary keys and foreign keys. Primary keys uniquely identify each tuple in a relation while foreign keys link two relations through their primary keys.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 61

Unit II

Structure of Relational Databases


INTRODUCTION
DBMS stands for Relational Database Management Systems..

ll modern database management systems like SQL, MS SQL Server, IBM DB2,
ORACLE, My-SQL and Microsoft Access are based on RDBMS.

t is called Relational Data Base Management System (RDBMS) because it is based


on relational model introduced by E.F. Codd.

uring 1970 to 1972, E.F. Codd published a paper to propose the use of relational
database model.

DBMS is originally based on that E.F. Codd's relational model invention.


What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS data is
structured in database tables, fields and records. Each RDBMS table consists of
database table rows. Each database table row consists of one or more database table
fields. 

RDBMS store the data into collection of tables, which might be related by common
fields (database table columns). RDBMS also provide relational operators to
manipulate the data stored into the database tables. Most RDBMS use SQL as
database query language.
FEATURES
rovides data to be stored in tables

ersists data in the form of rows and columns

rovides facility primary key, to uniquely identify the rows

reates indexes for quicker data retrieval

rovides a virtual table creation in which sensitive data can be stored and simplified query can be applied.(views)

haring a common column in two or more tables(primary key and foreign key)

rovides multi user accessibility that can be controlled by individual users.


COMPONENTS
The relational model is concerned with three components:
Data Structure

Data Integrity

Data Manipulation
Relational Data Structure

elation : A relation is a table with columns and rows.

ll data and relationships are represented in a two dimensional table called a


relation.

RDBMS requires only that the user perceive the database as tables. A relation
consists of number of records or row-wise information and column-wise
information. In other words, it represents the relation between rows and
columns of a two dimensional table.
ttribute: An attribute is a named column of a relation.

n the relational model, relations are used to hold information about


the objects to be represented in the database. A relation is
represented as a two-dimensional table in which the rows of the
table correspond to individual records and the table columns
correspond to attributes. Attributes can appear in any order and the
relation will still be the same relation, and therefore.
EXAMPLE
omain: A domain is the set of allowed values for one or more attributes.

domain defines the kind of data represented by an attribute. More


particular, a domain is the set of all possible values that an attribute may
validly contain. A Domain may also be defined as "A pool of values from
which actual values appearing in the column are drawn."

or Example: In college database Domain for Roll number column consists


of range of valid roll numbers of students studying in the college. If a
college has 5000 students, then the domain of Roll number may be from
1001 to 6000. Every table, that has a column Roll number, must refer to this
domain and can contain only those values that are permitted in domain.
DOMAIN FEATURES
ata Type-Basic data types are integer, decimal, or character. Most databases support variants of these plus
special data types for date and time.

ength-This is the number of digits or characters in the value. For example, a value of 5 digits or 40 characters.

ate Format-The format for date values such as dd/mm/yy or yy/mm/dd.

ange- The range specifies the lower and upper boundaries of the values of attribute may legally have.

onstraints-Are special resonations on allowed values. For example, the month in a date can never exceed 12 and
day of a month can never exceed 31.

ull support-Indicates whether the attribute can have null or unknown values.

efault value (if any)--The value an attribute will have if a value is not entered.
uple: A tuple is a row of a relation.The elements of a relation are the rows or tuples in the table.
In the Branch relation, each row contains four values, one for each attribute. Tuples can appear
in any order and the relation will still be the same relation, and therefore convey the same
meaning.

xtension of a Relation: The extension of a given relation is the set of tuples appearing in that
relation at any given instant of time.

he extension thus varies with time. It changes as tuples are created, destroyed, and updated. In
other words, an extension is the same as view of a table.

ntension of a Relation: It is the permanent part of the relation and independent of time. It
corresponds to what is specified in the relational scheme.

ntension is the combination of two things a naming structure and a set of integrity constraints.
egree: The degree of a relation is the number of attributes it
contains.

ardinality: The cardinality of a relation is the number of tuples


it contains.
ALTERNATIVE TERMINOLOGY

lternative terminologies for Relational model


DATA INTEGRITY

et of integrity rules, which ensure that the data is accurate.

elational integrity rules is based on the concept of relational keys.

elational Keys

here should not be any duplicate tuple within a relation. Therefore, we


should identify one or more attributes (called relational keys) that
uniquely identify each tuple in a relation.
TYPES OF KEYS
Key plays an important role in relational database; it is used for identifying
unique rows from table. It also establishes relationship among tables.
There are various types of keys used in RDBMS.
Primary Key
Super Key
Candidate Key
Alternate Key
Composite Key
Foreign Key
PRIMARY KEY
A primary is a column or set of columns in a table that uniquely identifies
tuples (rows) in that table.
POINTS TO THINKS
e denote the primary key by underlining the column name.

he value of primary key should be unique for each row of the table. Primary key column
cannot contain duplicate values.

rimary key column should not contain nulls.

rimary keys are not necessarily to be a single column; more than one column can also
be a primary key for a table. For e.g. {Stu_Id, Stu_Name}collectively can play a role of
primary key 
PROPERTIES
table: The value of a primary key must not change or should not become null Through out the life of an entity.
A stable primary key helps to keep the model stable.

F
or example: if we consider a patient record, the value for the primary key (Patientnumber) must not change
with time as would happen with the age field.

inimal: The primary key should be composed of the minimum number of fields that ensures the occurrences are
unique.

efinitive: A value must exist for every record at creation time. Because an entity occurrence cannot be
substantiated unless the primary key value also exists.

ccessible: Anyone who wants to create, read or delete a record must be able to see the Primary key value.
EXAMPLE
CustomerNo FirstName LastName
1 Sally Thompson
2 Sally Henderson
3 Harry Henderson
4 Sandra Wellington

CustomerNo is the primary key.


FOREIGN KEY
oreign keys are the columns of a table that points to the primary key of
another table. They act as a cross-reference between tables.

foreign key means that values in one table must also appear in another table.

he referenced table is called the parent table while the table with the foreign
key is called the child table. The foreign key in the child table will generally
reference a primary key in the parent table.
PROPERTIES

relational FK references a relational PK. An SQL FK references an SQL UNIQUE NOT NULL
(possibly a PK).

FK's referencing column types agree with corresponding referenced column types.

FK's referencing column values must appear as corresponding referenced column values.

relational table has no NULLs. An SQL FK subrow with a NULL does not constrain.

relational FK can be the empty set; SQL doesn't allow declaring that.
rderNo Employee Custome Supplier Price Item
No rNo
1 1 42 Harrison $235 Desk
2 4 1 Ford $234 Chair
3 1 68 Harrison $415 Table
4 2 112 Ford $350 Lamp
5 3 42 Ford $234 Chair
6 2 112 Ford $350 Lamp
7 2 42 Harrison $235 Desk
CANDIDATE KAY
The minimal set of attribute which can uniquely identify a tuple is known
as candidate key. For Example, STUD_NO in STUDENT relation.
The value of Candidate Key is unique and non-null for every tuple.

There can be more than one candidate key in a relation. For Example,
STUD_NO as well as STUD_PHONE both are candidate keys for
relation STUDENT.
The candidate key can be simple (having only one attribute) or
composite as well. For Example, {STUD_NO, COURSE_NO} is a
composite candidate key for relation STUDENT_COURSE.
SSecurityNo EmployeeNo FirstName LastName DateOfBirth DateEmploye
d
AF-23432334 1 Manny Tomanny 12 Apr 1966 01 May 1999

DQ-65444444 2 Rosanne Kolumns 21 Mar 1977 01 Jan 2000

GF-54354543 3 Cas Kade 01 May 1977 01 Apr 2002

JK-34333432 4 Norma Lyzation 03 Apr 1966 01 Apr 2002

VB-48565444 5 Juan Tomani 12 Apr 1966 01 Apr 2002

FG-23566553 6 Del Eats 01 May 1967 01 May 2004


EXAMPLE
Sid Sname Marks
S1 A 40
S2 A 40
S3 B 50
S2 B 50 Sid Sname Marks
S1 A 40
S2 B 20
S3 A 20
S4 C 50
n Table 1(Sid,Sname considered as CK)

n Table 2(SID is CK)

RIME attributes are the part of CK

C
andidate keys can be NULL. But the primary keys can never be NULL.

A
attribute can be primary key if it is candidate key but not having null values.
SUPER KEY

he set of attributes which can uniquely identify a tuple is known as


Super Key. For Example, STUD_NO, (STUD_NO,
STUD_NAME ) etc.

dding zero or more attributes to candidate key generates super key.

candidate key is a super key but vice versa is not true.


ALTERNATE KEY

he candidate key other than primary key is called as alternate key. For Example,
STUD_NO as well as STUD_PHONE both are candidate keys for relation
STUDENT but STUD_PHONE will be alternate key (only one out of many
candidate keys).

Alternate Candidate key


keys

K
Primary vs Alternate
Sid Bank Account Name Voter Id
1 ACC1 A V1
2 ACC2 B V2
3 ACC3 A V3
4 ACC4 B V4
5 ACC4 A NULL
Super Key

superkey is either a single or a combination of attributes that can be used to uniquely identify a database
record. A table might have many combinations that create superkeys.
R
ules

very CK is a super key.

very SK can’t be a CK.

inimal SK is the CK.

uper key=CK +Zero or More Attributes


EXAMPLE
Eid Name Salary
1 Alex 40,000
2 Carel 50,000
3 Alex 40,000
4 Null 50,000
COMPOSITE KEY

key that consists of more than one attribute to uniquely identify


rows (also known as records & tuples) in a table is called
composite key. It is also known as compound key.
cust_Id order_Id product_code product_count

C01 O001 P007 23

C02 O123 P007 19

C02 O123 P230 82

C01 O001 P890 42


RELATIONAL ALGEBRA
INTRODUCTION
Relational algebra is a procedural query language, which takes
instances of relations as input and yields instances of relations as
output. It uses operators to perform queries. An operator can be
either unary or binary. They accept relations as their input and
yield relations as their output. Relational algebra is performed
recursively on a relation and intermediate results are also
considered relations.
The fundamental operations of relational algebra are as follows −
Select

Project

Union

Set different

Cartesian product

Rename
SELECT OPERATION
t selects tuples that satisfy the given predicate from a relation.

otation used is σp(r).

stands for selection predicate and r stands for relation. p is prepositional logic formula which may
use connectors like and, or, and not. These terms may use relational operators like − =, ≠, ≥, < ,
>, ≤.

xample: σsubject = "database"(Books)

elects tuples from books where subject is 'database'.


subject = "database" and price = "450" or year >

"2010" (Books)
PROJECT OPERATION (∏)
t projects column(s) that satisfy a given predicate.

otation − ∏A1, A2, An (r)

here A1, A2 , An are attribute names of relation r.

uplicate rows are automatically eliminated, as relation is a set.

xample:

subject, author (Books)

elects and projects columns named as subject and author from the relation Books.
UNION OPERATION (∪)
It performs binary union between two given relations and is defined as −
r ∪ s = { t | t ∈ r or t ∈ s}

Notation − r U s

Where r and s are either database relations or relation result set


(temporary relation).

For a union operation to be valid, the following conditions must hold −


r, and s must have the same number of attributes.

Attribute domains must be compatible.

Duplicate tuples are automatically eliminated


Two relations are union compatible if
Both have same number of columns

Names of attributes are the same in both

Attributes with the same name in both relations have the same
domain
EXAMPLE

author (Books) ∪ ∏ author (Articles)

rojects the names of the authors who have either written a book or
an article or both.
SET DIFFERENCE (−)

he result of set difference operation is tuples, which are present in one


relation but are not in the second relation.

otation − r − s

author (Books) − ∏ author (Articles)

rovides the name of authors who have written books but not articles.
INTERSECT

This operator is used to pick the records from both the tables which
are common to them. In other words it picks only the duplicate
records from the tables. Even though it selects duplicate records
from the table, each duplicate record will be displayed only once in
the result set. It should have UNION Compatible columns to run
the query with this operator.
CARTESIAN PRODUCT (Χ)

ombines information of two different relations into one.

otation − r Χ s

here r and s are relations and their output will be defined as −

Χ s = { q t | q ∈ r and t ∈ s}.

author = 'tutorialspoint' (Books Χ Articles)


RENAME OPERATION (Ρ)

he results of relational algebra are also relations but without any


name. The rename operation allows us to rename the output
relation. 'rename' operation is denoted with small Greek letter rho ρ.

otation − ρ x (E)

here the result of expression E is saved with name of x.


EXAMPLES
SET OPERATION
SQL STATEMENTS
QL stands for Structured Query Language

QL lets you access and manipulate databases

QL is an ANSI (American National Standards Institute) standard.

QL can execute queries against a database

QL can retrieve data from a database

QL can insert records in a database

QL can update records in a database

QL can delete records from a database

QL can create new databases

QL can create new tables in a database

QL can create stored procedures in a database

QL can create views in a database

QL can set permissions on tables, procedures, and views


DDL
Defining How Your Data Is Stored
CREATE DATABASE is used to create a new, empty database.
DROP DATABASE is used to completely destroy an existing database.
USE is used to select a default database.
CREATE TABLE is used to create a new table, which is where your data
is actually stored.
ALTER TABLE is used to modify an existing table's definition.
DROP TABLE is used to completely destroy an existing table.
DESCRIBE shows the structure of a table.
Rename
DML
Manipulating Your Data
SELECT is used when you want to read (or select) your data.

INSERT is used when you want to add (or insert) new data.

UPDATE is used when you want to change (or update) existing data.

DELETE is used when you want to remove (or delete) existing data.

TRUNCATE is used when you want to empty (or delete) all data from
the template.
VIEWS
A view is nothing more than a SQL statement that is stored in the
database with an associated name. A view is actually a composition
of a table in the form of a predefined SQL query.

A view can contain all rows of a table or select rows from a table. A
view can be created from one or many tables which depends on the
written SQL query to create a view.
For any database, there are a number of possible views that may be
specified. Databases with many items tend to have more possible
views than databases with few items.

The best view for a particular purpose depends on the information the
user needs. For example, in a telephone directory, a user might want to
look up the name associated with a number, without concern for the
street address. The best view for this purpose would have two
columns: the phone numbers (in numeric sequence) in the first
column, and the name associated with each number in the second
column.

You might also like