0% found this document useful (0 votes)
14 views23 pages

DBMS Unit2

This document provides an overview of key concepts in the relational model of databases, including: - Relations consist of tuples made up of attributes with domains. Tuples are represented as rows in a table. - Keys such as candidate keys, primary keys, super keys, alternate keys and foreign keys are used to uniquely identify tuples and define relationships between tables. - An example schema diagram is shown for a university database with tables such as Instructor and Department related through foreign key constraints.

Uploaded by

pranay dodiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views23 pages

DBMS Unit2

This document provides an overview of key concepts in the relational model of databases, including: - Relations consist of tuples made up of attributes with domains. Tuples are represented as rows in a table. - Keys such as candidate keys, primary keys, super keys, alternate keys and foreign keys are used to uniquely identify tuples and define relationships between tables. - An example schema diagram is shown for a university database with tables such as Instructor and Department related through foreign key constraints.

Uploaded by

pranay dodiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Chapter 2:

Introduction to
Relational Model
Example of a Relation
attributes
(or columns)

tuples
(or rows)
Attribute Types
 The set of allowed values for each attribute is called the
domain of the attribute
 Attribute values are (normally) required to be atomic; that is,
indivisible
 The special value null is a member of every domain. Indicated
that the value is “unknown”
 The null value causes complications in the definition of many
operations
Relation Schema and Instance
 A1, A2, …, An are attributes

 R = (A1, A2, …, An ) is a relation schema

Example:
instructor = (ID, name, dept_name, salary)
 Formally, given sets D1, D2, …. Dn a relation r is a subset of
D1 x D2 x … x Dn
Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai  Di
 The current values (relation instance) of a relation are specified by
a table
 An element t of r is a tuple, represented by a row in a table
Relations are Unordered

 Order of tuples is irrelevant (tuples may be stored in an arbitrary order)


 Example: instructor relation with unordered tuples
Types of Keys in Relational Model
(Candidate, Super, Primary,
Alternate and Foreign)
 Keys are one of the basic requirements of a relational
database model. It is widely used to identify
the tuples(rows) uniquely in the table. We also use keys to
set up relations amongst various columns and tables of a
relational database.
 Different Types of Keys in the Relational Model
 Candidate Key
 Primary Key
 Super Key
 Alternate Key
 Foreign Key
 Composite Key
Candidate Key

 The minimal set of attributes that can uniquely identify a tuple is known as a candidate
key.
 It is a minimal super key.
 It is a super key with no repeated data is called a candidate key.
 The minimal set of attributes that can uniquely identify a record.
 It must contain unique values.
 It can contain NULL values.
 Every table must have at least a single candidate key.
 A table can have multiple candidate keys but only one primary key (the primary key cannot
have a NULL value, so the candidate key with a NULL value can’t be the primary key).
 The value of the Candidate Key is unique and may be null for a tuple.
 There can be more than one candidate key in a relationship.
Example
Conti..
Primary Key

 There can be more than one candidate key in relation out


of which one can be chosen as the primary key. For
Example, STUD_NO, as well as STUD_PHONE, are candidate
keys for relation STUDENT but STUD_NO can be chosen as
the primary key (only one out of many candidate keys).
 It is a unique key.
 It can identify only one tuple (a record) at a time.
 It has no duplicate values, it has unique values.
 It cannot be NULL.
 Primary keys are not necessarily to be a single column;
more than one column can also be a primary key for a
table.
Example
Super Key

 The set of attributes that can uniquely identify a tuple


is known as Super Key. For Example, STUD_NO,
(STUD_NO, STUD_NAME), etc. A super key is a group of
single or multiple keys that identifies rows in a table. It
supports NULL values.
 Adding zero or more attributes to the candidate key
generates the super key.
 A candidate key is a super key but vice versa is not true.
Example
Alternate Key

 The candidate key other than the primary key is called


an alternate key.
 All the keys which are not primary keys are called
alternate keys.
 It is a secondary key.
 It contains two or more fields to identify two or more
records.
 These values are repeated.
 Eg:- SNAME, and ADDRESS is Alternate keys
Example
Foreign Key

 If an attribute can only take the values which are present as values
of some other attribute, it will be a foreign key to the attribute to
which it refers. The relation which is being referenced is called
referenced relation and the corresponding attribute is called
referenced attribute the relation which refers to the referenced
relation is called referencing relation and the corresponding
attribute is called referencing attribute. The referenced attribute
of the referenced relation should be the primary key to it.
 It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
 It combines two or more relations (tables) at a time.
 They act as a cross-reference between the tables.
 For example, DNO is a primary key in the DEPT table and a non-key
in EMP
Example
Composite Key

 Sometimes, a table might not have a single


column/attribute that uniquely identifies all the records of
a table. To uniquely identify rows of a table, a combination
of two or more columns/attributes can be used. It still can
give duplicate values in rare cases. So, we need to find the
optimal set of attributes that can uniquely identify rows in
a table.
 It acts as a primary key if there is no primary key in a table
 Two or more attributes are used together to make a
composite key.
 Different combinations of attributes may give different
accuracy in terms of identifying the rows uniquely.
Example
Keys
 Let K  R
 K is a superkey of R if values for K are sufficient to identify a unique
tuple of each possible relation r(R)
 Example: {ID} and {ID,name} are both superkeys of instructor.
 Superkey K is a candidate key if K is minimal
Example: {ID} is a candidate key for Instructor
 One of the candidate keys is selected to be the primary key.
 which one?
 Foreign key constraint: Value in one relation must appear in another
 Referencing relation
 Referenced relation
 Example – dept_name in instructor is a foreign key from instructor
referencing department
Schema Diagram for University
Database

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy