RDM 2.docx

15

Transcript of RDM 2.docx

Page 1: RDM 2.docx
Page 2: RDM 2.docx

DATA MODEL

It is a collection of tools used for describing data, relationships among data, data semantics and consistency constraints.

This is the way which describes the design of the database at physical, logical and view level.Different categories of Data models are

• Relational Model

• Network Model

• Hierarchical Model

• ER Model

Hierarchical Data Model

o Developed in 1960.

o It represent database as upside down tree.

o Parent- Child relationship is present.

o It support only one to many relationship

o Starting point is called as Root , subpart is called as node and the last node called as leaf node.

Network Data Model

o Developed in 1964 and standardized in 1971.

o It represent database as a arbitrary graph.

o There is no parent-child relationship between nodes.

o It supports many to many relationship.

Page 3: RDM 2.docx

ER Model

o ER model is a Entity Relationship Model.

o It is a graphical representation of database including relationships, constraints, roles and cardinalities in database.

o Components of ER model

o Entity Set

o Relationship Set

o Attribute

Entity

An entity is a “thing” or “object” in the real world that is distinguishable from all other objects.

For example, each person in an enterprise is an entity. An entity has a set of properties, and the values for some set of properties may uniquely identify an entity.

Attribute

Attributes are descriptive properties possessed by each member of an entity set. An entity is represented by a set of attributes.

For example Possible attributes of the customer entity set are customer_id, customer-name, customer_street and customer_city.

Relationship

A relationship is an association among several entities.

For example, we can define a relationship that associates customer Hayes with loan L-15. This relationship specifies that Hayes is a customer with loan number L-15.

Page 4: RDM 2.docx

Symbols for ER DiagramsRectangles, which represent entity sets.

Ellipses, which represent attributes.

Diamonds, which represent relationship sets.

Lines, which link attributes to entity sets and entity sets to relationship sets.

Double ellipses, which represent multivalued attributes.

Dashed ellipses, which denote derived attributes.

Double rectangles, which represent weak entity sets

Types of Attributes :

• Simple Attribute

• Primary Key Attribute

• Multivalued Attribute

• Derived Attribute

• Composite Attribute

Page 5: RDM 2.docx

Role of Entity

The function that an entity plays in a

Relationship is called that entity’s role.

We indicate roles in E-R diagrams by labeling the lines that connect diamonds to rectangles. Figure 2.12 shows the role indicators manager and worker between the employee entity set and the works-for relationship set.

Strong Entity Set

• An entity set that has a primary key is termed a strong entity set.

Weak Entity Set

• An entity set may not have sufficient attributes to form a primary key. Such an entity set is termed a weak entity set.

• For a weak entity set to be meaningful, it must be associated with another entity set, called the identifying or owner entity set.

Page 6: RDM 2.docx

Types of Relationships / Mapping Cardinalities

Query Language

• A query language is a language in which a user requests information from the database.

• These languages are usually on a level higher than that of a standard database programming language.

• Query languages can be categorized as either procedural or nonprocedural.

• In a procedural language, the user instructs the system to perform a sequence of operations on the database to compute the desired result.

For example Relational Algebra

• In a nonprocedural language, the user describes the desired information without giving a specific procedure for obtaining that information.

For Example Relational Calculus

Relational Algebra

o The relational algebra is a procedural query language.

o It consists of a set of operations that take one or two relations as input and produce a new relation as their result.

o The fundamental operations in the relational algebra are select, project, union, set difference, Cartesian product, and rename.

Unary operations

Binary operations

Unary Operations

o Select

o Project

o Rename

Binary Operations

o Union

o Intersection

o Set Difference

PAN CARDPERSON

Page 7: RDM 2.docx

o Cartesian Product

Select Operationo Select records from relation that satisfy the selection condition or search condition.o Lower case Greek letter sigma (σ) is used to denote selection.o Selection criteria for selection condition appears as subscript to sigma.o Consider schema BOOK (B_ID, TITLE, AUTHOR, YEAR, PRICE).o Syntax

σ(Selection condition) (Relation)o Example

“Extract record of books having price less than 450/-”σ(price < 450 ) (BOOK)

Project Operationo Project operation display certain columns or attributes from table/relation.o Lower case Greek letter pi (π) is used to denote project operation.o Column names appears as subscript to pi.o Consider schema BOOK (B_ID, TITLE, AUTHOR, YEAR, PRICE).o Syntax

π(Column Name1, Column Name2, ….., Column Name n) (Relation)o Example

“Extract title and author of books from BOOK relation”

π(title , author) (BOOK)Rename Operation

• Rename operation use to rename relation/table name as well as attribute/column names.• Lower case Greek letter rho (ρ) is used to denote rename operation.

1. Rename only relation/table name.2. Rename only attribute/column names.3. Rename both relation/table name and attribute/column names at a time.

1. Rename only relation/table name.Syntax: ρs (R)

New name of relation old name of relation

Example: ρarkp_stud (student)1. Rename only attribute/column names.2. Rename both relation/table name and attribute/column names at a time.

Rename attribute/column names

Syntax : ρ (new names for attributes) (R)

name of relation

Example : ρ (s_rn, s_name, s_class) (student)

Rename relation/table name as well as attribute names

Syntax: ρs (new names for attributes) (R)

New name of relation old name of relation

Example: ρarkp_stud (s_rn, s_name, s_class) (student)

Page 8: RDM 2.docx

Union Operationo Union operation is a binary operation.o It returns all data values that appear in either or both of the two relations.o Denoted by symbol ∪.

Syntax: Relation 1 ∪ Relation 2

Example: Π Cust_name (borrower) ∪ Π Cust_name (depositor)

Intersection Operationo Intersection operation is also a binary operation.o It returns all data values which are common in two or more relations.o Denoted by symbol ∩.

Syntax: Relation 1 ∩ Relation 2Example:Π Cust_name (borrower ) ∩ Π Cust_name (depositor)

Set Difference OperationSet Difference operation is also a binary operation.Set Difference operation allows us to find tuples which are present in first relation but not in other relation.Denoted by symbol “ - “.Syntax: Relation 1 Relation 2Example:Π Cust_name (borrower ) - Π Cust_name (depositor)

Page 9: RDM 2.docx

Cartesian product Operation

Cartesian product operation is also a binary operation.

Cartesian product operation combines two or more relations in such a way that each row of one relation combine with each row of other relation.

Denoted by symbol “× “.

Syntax: Relation 1 × Relation 2

Example:

Borrower × depositor

Relational Calculus

• It is a non-procedural query language while relational algebra is procedural.

• There are two variant of relational calculus

1) Tuple Relational Calculus (TRC)

2) Domain Relational Calculus (DRC)

Page 10: RDM 2.docx

Tuple Relational Calculus

o In TRC, All operations are depend on tuples.

o A tuple variable is a variable that takes tuples of a particular relation. Tuple variable has same number of columns as in relation.

o A tuple relational calculus query has the form

{T | p (T)}

Where T is tuple variable

P (T) is formula that operates/describe tuple variable (T)

o Example

Query = “find all sailors with a rating above 7”

The tuple relational calculus query will be

{S | S ϵ sailors ˄ S.rating > 7 ˄ S.AGE<30}

Domain Relational Calculus

o In DRC, All operations are depend on attribute domains (columns).

o A domain variable is a variable that contains values from some attribute domains.

o A domain relational calculus query has the form

{(X1, X2,… Xn) | p(X1, X2,… Xn)

Where each Xi is either a domain variable or constant

P(X1, X2,…., Xn) is formula that operates/describe tuple variable (T)

o Example

Query = “find all sailors with a rating above 7 AND AGE IS BELOW 30”

The tuple relational calculus query will be

{(I, N, T, A) | (I, N, T, A) ϵ sailors ˄ T > 7 ˄ A<30}

Page 11: RDM 2.docx

FUNCTIONAL DEPENDENCY

If AB C then following condition must be present in relation R

T1. (AB) = (a1b1)

&

T2. (AB)= (a1b1)

Now consider

T1(C) = C1

T2(C) = C1

Therefore we can say that

AB C

NORMALIZATION

Normalization can be defined as a process of

o Minimizing Redundancy

o Minimizing Inconsistency

o Minimizing the insertion, deletion and update anomalies from the database.

There are different type of normal forms having their own condition OR criteria for normalization. Different normal forms are

First Normal form ( 1NF )

Second Normal form (2 NF )

Third Normal form (3 NF )

Boyce/Codd Normal form (BCNF )

Page 12: RDM 2.docx

First Normal form (1NF)

“A relation is in 1 NF if and only if every attribute of a relation is single OR atomic”

Second Normal Form (2NF )

“A relation is in second normal if and only if it is in 1NF every nonprime attribute is fully functional depend on primary key of a relation.”

Third Normal Form (3NF)

“A relation is in third normal form if and only if, it is in 2NF and there is no transitive dependency in a relation.”

Page 13: RDM 2.docx

Boyc Codd Normal Form (BCNF)

“A relation is in BCNF if and only if, it is in 2NF and every determinant is a candidate key.”

Client No, interviewDate (Primary Key)

interviewDate, staffNo roomNo