13
Lecture 7 Relational Database Management System

Lecture 07 relational database management system

Embed Size (px)

Citation preview

Page 1: Lecture 07 relational database management system

Lecture 7

Relational Database Management System

Page 2: Lecture 07 relational database management system

The Relational Model

• Due to Codd.• Everything is represented as a relation. • A database therefore is a collection of tables, each of

which has a unique name, and each of which is described by a schema.

• In addition, Codd defined a data manipulation language.

Page 3: Lecture 07 relational database management system

Example of Schemas in the Relational Model

• Example of a representation of entity sets:

Student(sid,name,addr)

Course(cid,title,eid)

Empl(eid, ename, deptid)

Dept(deptid, dname, loc)• Primary keys are underlined.• Recall that a primary key is one that uniquely identifies an entity.• An entity is a row in a table.

Page 4: Lecture 07 relational database management system

Relational Databases:Basic Concepts I

• Attribute:– A column in a table

• Domain– The set of values from which the values of an attribute are

drawn.

• Null value– A special value, meaning “not known” or “not applicable”.

• Relation schema– A set of attribute names

Page 5: Lecture 07 relational database management system

Relational Databases: Basic Concepts II

• Tuple– A set of values, one for each attribute in the relation scheme

over which the tuple is defined, i.e. a mapping from attributes to the appropriate domains

• Relation instance– A set of tuples over the scheme of the relation

Page 6: Lecture 07 relational database management system

Relational Databases:Basic Concepts III

• Relational Database– A set of relations, each with a unique name

• Normalized Relation– A relation in which every value is atomic (non-decomposable).

Hence, every attribute in every tuple has a single value.

Page 7: Lecture 07 relational database management system

Keys

• Candidate Key– A minimal set of attributes that uniquely identifies a

tuple

• Primary Key– The candidate key chosen as the identifying key of

the relation

• Alternate Key– Candidate keys which are not primary keys

Page 8: Lecture 07 relational database management system

• Foreign Key– An attribute (or set of attributes) in table R1

which also occurs as the primary key of relation R2.

– R2 is called the referenced relation. – Foreign keys are also called connection

keys or reference attributes.

Page 9: Lecture 07 relational database management system

Integrity Rules: Entity Constraint

• Entity constraint– All attributes in a primary key must be non-

null.– Motivation: If the primary key uniquely

identifies an entity in an entity set, then we must ensure that we have all the relevant information

Page 10: Lecture 07 relational database management system

Integrity Rules:Referential Integrity

• Referential integrity– A database cannot contain a tuple with a

value for a foreign key that does not match a primary key value in the referenced relation.

– Or, a foreign key must refer to a tuple that exists.

– Motivation: If referential integrity were violated, we could have relationships between entities that we do not have any information about.

Page 11: Lecture 07 relational database management system

Codd Rules

• Rules for a Database to qualify as Relational Database1. Information Rule2. Guaranteed Access Rule3. Comprehensive Data Sub-language Rule4. View Update Rule5. High Level Insert, Update and Delete6. Physical Data Independence7. Logical Data Independence8. Integrity Independence9. Non Subversion Rule10.Systematic Treatment of Null Values11.Database Description Rule12.Distribution Independence

Page 12: Lecture 07 relational database management system

Data Manipulation Languages

• In order for a database to be useful, it should be possible to store and retrieve information from it. This is the role of the data manipulation language.

• One of the attractions of the relational data model is that

it comes with a well-defined data manipulation language.

Page 13: Lecture 07 relational database management system

Types of DML

• Two types of data manipulation languages– Navigational (procedural)

• The query specifies (to some extent) the strategy used to find the desired result e.g. relational algebra.

– Non-navigational(non-procedural)• The query only specifies what data is wanted, not

how to find it e.g. relational calculus.