Unit 2 Structure of Rdbms
Unit 2 Structure of Rdbms
ll modern database management systems like SQL, MS SQL Server, IBM DB2,
ORACLE, My-SQL and Microsoft Access are based on RDBMS.
uring 1970 to 1972, E.F. Codd published a paper to propose the use of relational
database model.
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
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)
Data Integrity
Data Manipulation
Relational Data Structure
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.
ength-This is the number of digits or characters in the value. For example, a value of 5 digits or 40 characters.
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.
elational Keys
he value of primary key should be unique for each row of the table. Primary key column
cannot contain duplicate values.
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
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
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 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).
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
Project
Union
Set different
Cartesian product
Rename
SELECT OPERATION
t selects tuples that satisfy the given predicate from a relation.
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 − =, ≠, ≥, < ,
>, ≤.
"2010" (Books)
PROJECT OPERATION (∏)
t projects column(s) that satisfy a given predicate.
xample:
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
Attributes with the same name in both relations have the same
domain
EXAMPLE
rojects the names of the authors who have either written a book or
an article or both.
SET DIFFERENCE (−)
otation − r − s
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 (Χ)
otation − r Χ s
Χ s = { q t | q ∈ r and t ∈ s}.
otation − ρ x (E)
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.