database fundamental keys

Post on 15-Jan-2017

131 Views

Category:

Data & Analytics

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

www.company.com

Database fundamental Keys

By: Fouzia NazMohammad Ali Jinnah University (Lecturer)

1

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.

www.company.com

Table

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]

www.company.com

Table Customers

www.company.com

Field (Column)

a field

Customers

www.company.com

Record (Row)

a record

Customers

www.company.com

Primary Key

primary key fields

Roles (Performances)

A primary key can consist of more than one field.

www.company.com

Foreign Key

foreign key field

primary key fieldparent table

Directors

Movieschild tablerelationship

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.

www.company.com

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

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)

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.

www.company.com14

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,

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.

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.

www.company.com

Example

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

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

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

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

www.company.com

Alternative Notation for Cardinality Limits

• Cardinality limits can also express participation constraints

www.company.com

E-R Diagram with a Ternary Relationship

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).

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.

www.company.com

Specialization Example

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.

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.

www.company.com

E-R Diagram for a Banking Enterprise

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.

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

www.company.com

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

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

top related