database fundamental keys

34
www.company.com Database fundamental Keys By: Fouzia Naz Mohammad Ali Jinnah University (Lecturer) 1

Upload: tehnanali

Post on 15-Jan-2017

131 views

Category:

Data & Analytics


0 download

TRANSCRIPT

Page 1: Database fundamental keys

www.company.com

Database fundamental Keys

By: Fouzia NazMohammad Ali Jinnah University (Lecturer)

1

Page 2: Database fundamental keys

www.company.com

Table• “A table is the primary unit of physical storage for

data in a database.”1

• Usually a database contains more than one table.

1) Stephens, R.K. and Plew. R.R., 2001. Database Design. SAMS, Indianapolis , IN.

Page 3: Database fundamental keys

www.company.com

Table

Page 4: Database fundamental keys

www.company.com

A Database with Multiple Tables

Publishers Books Customers

Authors Inventory Orders

1) Stephens, R.K. and Plew. R.R., 2001. Database Design. SAMS, Indianapolis , IN. (with slight changes by V.G.D.)

[1]

Page 5: Database fundamental keys

www.company.com

Table Customers

Page 6: Database fundamental keys

www.company.com

Field (Column)

a field

Customers

Page 7: Database fundamental keys

www.company.com

Record (Row)

a record

Customers

Page 8: Database fundamental keys

www.company.com

Primary Key

primary key fields

Roles (Performances)

A primary key can consist of more than one field.

Page 9: Database fundamental keys

www.company.com

Foreign Key

foreign key field

primary key fieldparent table

Directors

Movieschild tablerelationship

Page 10: Database fundamental keys

www.company.com10

The Key•A key is a set of attributes that can be used•to identify or access a particular entity instance of an entity type (or out of an entity set).•An entity type may have many instances, from a few to several thousands and even more.•If we want to pick a particular/single instance, and many times we do need it, then key is the solution.

Page 11: Database fundamental keys

www.company.com

The Key•Super Key•Candidate Key• Primary Key• Alternate Key• Secondary Key•Foreign Key

Page 12: Database fundamental keys

www.company.com

Super key•A super key is a set of one or more attributes which taken collectively.• It allow us to identify uniquely an entity instance in the entity set

like program and course code.

•An entity type, its defining attributes and super key (underlined)

Page 13: Database fundamental keys

www.company.com

Candidate key A super key for which no subset is a superkey is called a candidate key.• The minimal super key is the candidate key.• It means that there are two conditions for• the candidate key.• One, it identifies the entity instances uniquely, as is required in case of

super key. Second, it should be minimum, that subset of candidate key is a key.

Page 14: Database fundamental keys

www.company.com14

Page 15: Database fundamental keys

www.company.com

Primary keyPrimary key•A candidate key chosen by the database• designer to act as key is the primary key.• An entity type may have more than one• candidate keys, in that case the database• Designer has to designate one of them as a

primary key,

Page 16: Database fundamental keys

www.company.com

Alternate keys• Candidate keys which are not chosen as

the primary key are known as alternate keys also known as secondary key.

Page 17: Database fundamental keys

www.company.com

Secondary key• Secondary Key. An entity may have one or

more choices for the primary key. Collectively these are known as candidate keys. One is selected as the primary key.

Page 18: Database fundamental keys

www.company.com

Example

Page 19: Database fundamental keys

www.company.com

Cardinality Constraints

• We express cardinality constraints by drawing either a directed line (), signifying “one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.

• One-to-one relationship:– A customer is associated with at most one loan via the

relationship borrower– A loan is associated with at most one customer via borrower

Page 20: Database fundamental keys

www.company.com

One-To-Many Relationship

• In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower

Page 21: Database fundamental keys

www.company.com

Many-To-One Relationships

• In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower

Page 22: Database fundamental keys

www.company.com

Many-To-Many Relationship

• A customer is associated with several (possibly 0) loans via borrower• A loan is associated with several (possibly 0) customers via borrower

Page 23: Database fundamental keys

www.company.com

Alternative Notation for Cardinality Limits

• Cardinality limits can also express participation constraints

Page 24: Database fundamental keys

www.company.com

E-R Diagram with a Ternary Relationship

Page 25: Database fundamental keys

www.company.com

Extended E-R Features: Specialization

• Top-down design process; we designate subgroupings within an entity set that are distinctive from other entities in the set.

• These sub groupings become lower-level entity sets that have attributes or participate in relationships that do not apply to the higher-level entity set.

• Depicted by a triangle component labeled ISA (E.g. customer “is a” person).

Page 26: Database fundamental keys

www.company.com

Cont..

• Attribute inheritance – a lower-level entity set inherits all the attributes and relationship participation of the higher-level entity set to which it is linked.

• Row of any table is called tuple.

Page 27: Database fundamental keys

www.company.com

Specialization Example

Page 28: Database fundamental keys

www.company.com

Extended ER Features: Generalization

• A bottom-up design process – combine a number of entity sets that share the same features into a higher-level entity set.

• Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way.

• The terms specialization and generalization are used interchangeably.

Page 29: Database fundamental keys

www.company.com

AggregationAggregation is a process when relation between two entity is treated as a single entity. Here the relation between Center and Course, is acting as an Entity in relation with Visitor.

Page 30: Database fundamental keys

www.company.com

E-R Diagram for a Banking Enterprise

Page 31: Database fundamental keys

www.company.com

Relational Model Concepts• A Relation is a mathematical concept based on

the ideas of sets

• The model was first proposed by Dr. E.F. Codd :– "A Relational Model for Large Shared Data

Banks• The above paper caused a major revolution in

the field of database management.

Page 32: Database fundamental keys

www.company.com

Relational Model Concepts• The relational model represents the

database as a collection of relations

• Each relation resembles a table of values

• When a relation is thought of as a table of values, each row in the table represents a collection of related data values

Page 33: Database fundamental keys

www.company.com

Formal Terminology• A row is called a tuple• A column header is called an attribute• The table is called relation

Page 34: Database fundamental keys

www.company.com

Atomic Values• A Domain D is a set of atomic values.

• Atomic means that each value in the domain is indivisible as far as the relational model is concerned

• It means that if we separate an atomic value, the value itself become meaningless, for example:– SSN– Local_phone_number– Names– Employee_ages