SlideShare a Scribd company logo
Relational Model
Rajeev Srivastava
ToC
• Relation
• Tuples
• Cardinality
• Attribute
• Degree/Arity
• Domains
• Relation vs. Table
2
• Candidate Key
• Super Key
• Primary Key
• Composite Key
• Foreign Key
• Integrity Rules
RAJEEVS@CDAC.IN
Relation
In Relational Model data is modelled in form of Relations represented by tabular
structure.
Consider the relation EMPLOYEE represented by the following table:
3
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
RAJEEVS@CDAC.IN
Tuples in a Relation
A relation is a set of tuples; each row here is a tuple :
4
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
1
2
3
4
5
7
6
RAJEEVS@CDAC.IN
Cardinality of a Relation
No of Tuples in a Relation at a point in time.
Cardinality = 7
5
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
1
2
3
4
5
7
6
RAJEEVS@CDAC.IN
Attribute in a Relation
An attribute represents a quality/information about an entity.
A tuple consists of Attribute values.
6
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
RAJEEVS@CDAC.IN
Degree (=Arity) of a Relation
A degree or arity of a Relation is the number of attributes in it.
Degree = 8
7
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
RAJEEVS@CDAC.IN
Domains
Each attribute has a domain associated with it.
Attribute values in a relation are restricted to the values from its domain.
8
EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode
DEPT
ACCO
PURC
COUR
DESIG
PE
TO
STO
RAJEEVS@CDAC.IN
Consider the Employee relation defined as :
create table EMPLOYEE(
EmpCode integer(4),
Name char(30),
Desig char(4),
Grade integer(4),
JoinDate date,
Basic integer(7),
Gender char(1),
DeptCode char(4) )
9RAJEEVS@CDAC.IN
Domains of Attributes of Employee Relation :
EmpCode set of all 4-digit numbers
Name set of all 30-alpha characters
Desig set of all designation codes
Grade set of all grade values
JoinDate set of all dates (in a given range)
Basic set of all possible values for basic
Gender set {'M','F‘, ‘T’}
DeptCode set of all dept codes
10RAJEEVS@CDAC.IN
A Relation may be represented as a Table where
11
Relation Table
Tuple Row/Record
Attribute Column
Degree/Arity No of Columns in the table
Cardinality No or Rows in the table
Domain Pool of acceptable values for a
column
Primary Key Unique Identifier
RAJEEVS@CDAC.IN
But, a Relation is not a Table, because :
• A table has an inherent order for rows; there is no concept of order for tuples
in a relation.
• A relation must have a primary key; a table need not have an identifier.
• The tuples in a relation must be unique; there is no such restriction for tables
12RAJEEVS@CDAC.IN
Relation : Observations
• A Relation is a set of tuples.
• A Relation is time-variant.
• A Relation cannot have duplicate tuples.
• Tuples in a Relation are unordered.
• Values are Atomic.
• Attribute values are of same kind.
• A Relation is a subset of the Cartesian Product of a set of domains.
13RAJEEVS@CDAC.IN
Candidate Key & Super Key
A set of attributes is said to be Candidate Key if and only if it satisfies the
following time-independent properties:
Uniqueness property: No two distinct tuples have the same value for the key.
Minimality property: None of the attributes of the key can be discarded from
the key without destroying the uniqueness property.
A Super Key is a Non-Minimal Candidate Key. Its a set of one or more columns in
a table for which no two rows can have the exact same values.
An Alternate Key is a candidate key that is not the primary key.
14RAJEEVS@CDAC.IN
Candidate Key?
create table EMPLOYEE(
EmpCode integer(4),
Name char(30),
Desig char(4),
Grade integer(4),
JoinDate date,
Basic integer(7),
Gender char(1),
DeptCode char(4) )
15RAJEEVS@CDAC.IN
Candidate Key?
create table EMPLOYEE (
EmpCode integer(4),
Name char(30),
Desig char(4),
Grade integer(4),
JoinDate date,
Basic integer(7),
Gender char(1),
DeptCode char(4),
Email char(100),
MobileNo char(16) )
16RAJEEVS@CDAC.IN
Primary Key
is a candidate key that have following two qualities -
• Uniquely identifies a tuple in a relation
• Must NOT be NULL
*Should be selected from candidate keys such that it never/rarely changes.
17RAJEEVS@CDAC.IN
Primary Key?
create table EMPLOYEE (
EmpCode integer(4),
Name char(30),
Desig char(4),
Grade integer(4),
JoinDate date,
Basic integer(7),
Gender char(1),
DeptCode char(4),
Email char(100),
MobileNo char(16) )
18RAJEEVS@CDAC.IN
Composite Key
• A candidate key with two or more attributes that uniquely identifies the tuple in a
Relation.
• Also called as compound key
Composite Primary Key
• A primary key which is a composite key is called as Composite Primary Key.
19RAJEEVS@CDAC.IN
Can we have more than one primary key
in a table?
No. We can not.
People who are new to RDBMS are often get confused with the restriction of single Primary Key
in a table and the concept of Composite Key. To clarify the same -
A table can have only one Primary Key.
The Primary Key can be defined on a single column or more than one columns. If the Primary
Key is defined using more that one columns, it is known as a Composite Key (or Composite
Primary Key).
Therefore, a Composite Key in a table does not mean that there are more than one Primary Keys
in the table. Instead, a Composite Key uses more than one columns to define a (Single) Primary
Key.
RAJEEVS@CDAC.IN 20
Foreign Key
• A Foreign Key is a set of attributes in one relation whose values are required to match
one of the values of the primary key of the same or different relation.
• There can be more than one foreign key in a given relation.
21RAJEEVS@CDAC.IN
Identify a relation in any system/business, define its
Attributes, Domain for each attribute and find out Primary,
Key, Foreign Keys, Candidate Keys, Super Key in the relation.
Foreign Key(s)?
create table EMPLOYEE(
EmpCode integer(4),
Name char(30),
Desig char(4),
Grade integer(4),
JoinDate date,
Basic integer(7)),
Gender char(1),
DeptCode char(4) )
create table DEPT(
DeptCode char(4),
DeptName char(30),
Location char(10) )
22RAJEEVS@CDAC.IN
Integrity Rules
Entity Integrity: Implemented through Primary Key
“No Attribute participating in the primary key of a relation may accept null
values”
Guarantees that each tuple will have a unique identity.
Referential Integrity: Implemented through Foreign Key
“Values of the foreign key (a) must be either null, or (b) if non-null, must match
with the primary key value of some tuple of the `parent’ relation. The reference
can be to the same relation”
*Foreign Key is also know as Reference/Referential key.
23RAJEEVS@CDAC.IN
Relational Database Operations
• SELECTION: This selects some or all of the records in a table.
Through WHERE Clause
• PROJECTION: This limits columns from a table.
Through SELECT Clause
• UNION
• INTERSECTION
• DIFFERENCE
• JOIN
• CARTESIAN PRODUCT
RAJEEVS@CDAC.IN 24

More Related Content

What's hot

Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
Jafar Nesargi
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
Kumar
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
koolkampus
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management system
emailharmeet
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
Jafar Nesargi
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
eidah20
 

What's hot (20)

Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1Chapter 2 Relational Data Model-part1
Chapter 2 Relational Data Model-part1
 
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database ConstraintsThe Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 
The relational data model part[1]
The relational data model part[1]The relational data model part[1]
The relational data model part[1]
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Lecture 07 relational database management system
Lecture 07 relational database management systemLecture 07 relational database management system
Lecture 07 relational database management system
 
Database : Relational Data Model
Database : Relational Data ModelDatabase : Relational Data Model
Database : Relational Data Model
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
Chapter-6 Relational Algebra
Chapter-6 Relational AlgebraChapter-6 Relational Algebra
Chapter-6 Relational Algebra
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Chapter-9 Normalization
Chapter-9 NormalizationChapter-9 Normalization
Chapter-9 Normalization
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013
 
Chapter-8 Relational Database Design
Chapter-8 Relational Database DesignChapter-8 Relational Database Design
Chapter-8 Relational Database Design
 
Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2Chapter3 the relational data model and the relation database constraints part2
Chapter3 the relational data model and the relation database constraints part2
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 

Similar to Relational Model - An Introduction

4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
LPhct2
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
khoahuy82
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
lavya3
 

Similar to Relational Model - An Introduction (20)

Advance database system(part 5)
Advance database system(part 5)Advance database system(part 5)
Advance database system(part 5)
 
Data model
Data modelData model
Data model
 
DBMS-Unit-2.pptx
DBMS-Unit-2.pptxDBMS-Unit-2.pptx
DBMS-Unit-2.pptx
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
Integrity Constraints in Database Management System.ppt
Integrity Constraints in Database Management System.pptIntegrity Constraints in Database Management System.ppt
Integrity Constraints in Database Management System.ppt
 
2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903
 
Create table
Create tableCreate table
Create table
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
8. OPERATORS IN SQL.pptx
8.  OPERATORS IN SQL.pptx8.  OPERATORS IN SQL.pptx
8. OPERATORS IN SQL.pptx
 
RDBMS
RDBMSRDBMS
RDBMS
 
Structured Query Language (SQL) - An Introduction
Structured Query Language (SQL) - An IntroductionStructured Query Language (SQL) - An Introduction
Structured Query Language (SQL) - An Introduction
 
Relational Model on Database management PPT
Relational Model on Database management PPTRelational Model on Database management PPT
Relational Model on Database management PPT
 
ER diagram
ER diagramER diagram
ER diagram
 
Relational model
Relational modelRelational model
Relational model
 
Relational model
Relational modelRelational model
Relational model
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 

Recently uploaded

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 

Relational Model - An Introduction

  • 2. ToC • Relation • Tuples • Cardinality • Attribute • Degree/Arity • Domains • Relation vs. Table 2 • Candidate Key • Super Key • Primary Key • Composite Key • Foreign Key • Integrity Rules RAJEEVS@CDAC.IN
  • 3. Relation In Relational Model data is modelled in form of Relations represented by tabular structure. Consider the relation EMPLOYEE represented by the following table: 3 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode RAJEEVS@CDAC.IN
  • 4. Tuples in a Relation A relation is a set of tuples; each row here is a tuple : 4 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode 1 2 3 4 5 7 6 RAJEEVS@CDAC.IN
  • 5. Cardinality of a Relation No of Tuples in a Relation at a point in time. Cardinality = 7 5 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode 1 2 3 4 5 7 6 RAJEEVS@CDAC.IN
  • 6. Attribute in a Relation An attribute represents a quality/information about an entity. A tuple consists of Attribute values. 6 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode RAJEEVS@CDAC.IN
  • 7. Degree (=Arity) of a Relation A degree or arity of a Relation is the number of attributes in it. Degree = 8 7 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode RAJEEVS@CDAC.IN
  • 8. Domains Each attribute has a domain associated with it. Attribute values in a relation are restricted to the values from its domain. 8 EmpCode Name Desig Grade JoinDate BasicSalary Gender DeptCode DEPT ACCO PURC COUR DESIG PE TO STO RAJEEVS@CDAC.IN
  • 9. Consider the Employee relation defined as : create table EMPLOYEE( EmpCode integer(4), Name char(30), Desig char(4), Grade integer(4), JoinDate date, Basic integer(7), Gender char(1), DeptCode char(4) ) 9RAJEEVS@CDAC.IN
  • 10. Domains of Attributes of Employee Relation : EmpCode set of all 4-digit numbers Name set of all 30-alpha characters Desig set of all designation codes Grade set of all grade values JoinDate set of all dates (in a given range) Basic set of all possible values for basic Gender set {'M','F‘, ‘T’} DeptCode set of all dept codes 10RAJEEVS@CDAC.IN
  • 11. A Relation may be represented as a Table where 11 Relation Table Tuple Row/Record Attribute Column Degree/Arity No of Columns in the table Cardinality No or Rows in the table Domain Pool of acceptable values for a column Primary Key Unique Identifier RAJEEVS@CDAC.IN
  • 12. But, a Relation is not a Table, because : • A table has an inherent order for rows; there is no concept of order for tuples in a relation. • A relation must have a primary key; a table need not have an identifier. • The tuples in a relation must be unique; there is no such restriction for tables 12RAJEEVS@CDAC.IN
  • 13. Relation : Observations • A Relation is a set of tuples. • A Relation is time-variant. • A Relation cannot have duplicate tuples. • Tuples in a Relation are unordered. • Values are Atomic. • Attribute values are of same kind. • A Relation is a subset of the Cartesian Product of a set of domains. 13RAJEEVS@CDAC.IN
  • 14. Candidate Key & Super Key A set of attributes is said to be Candidate Key if and only if it satisfies the following time-independent properties: Uniqueness property: No two distinct tuples have the same value for the key. Minimality property: None of the attributes of the key can be discarded from the key without destroying the uniqueness property. A Super Key is a Non-Minimal Candidate Key. Its a set of one or more columns in a table for which no two rows can have the exact same values. An Alternate Key is a candidate key that is not the primary key. 14RAJEEVS@CDAC.IN
  • 15. Candidate Key? create table EMPLOYEE( EmpCode integer(4), Name char(30), Desig char(4), Grade integer(4), JoinDate date, Basic integer(7), Gender char(1), DeptCode char(4) ) 15RAJEEVS@CDAC.IN
  • 16. Candidate Key? create table EMPLOYEE ( EmpCode integer(4), Name char(30), Desig char(4), Grade integer(4), JoinDate date, Basic integer(7), Gender char(1), DeptCode char(4), Email char(100), MobileNo char(16) ) 16RAJEEVS@CDAC.IN
  • 17. Primary Key is a candidate key that have following two qualities - • Uniquely identifies a tuple in a relation • Must NOT be NULL *Should be selected from candidate keys such that it never/rarely changes. 17RAJEEVS@CDAC.IN
  • 18. Primary Key? create table EMPLOYEE ( EmpCode integer(4), Name char(30), Desig char(4), Grade integer(4), JoinDate date, Basic integer(7), Gender char(1), DeptCode char(4), Email char(100), MobileNo char(16) ) 18RAJEEVS@CDAC.IN
  • 19. Composite Key • A candidate key with two or more attributes that uniquely identifies the tuple in a Relation. • Also called as compound key Composite Primary Key • A primary key which is a composite key is called as Composite Primary Key. 19RAJEEVS@CDAC.IN
  • 20. Can we have more than one primary key in a table? No. We can not. People who are new to RDBMS are often get confused with the restriction of single Primary Key in a table and the concept of Composite Key. To clarify the same - A table can have only one Primary Key. The Primary Key can be defined on a single column or more than one columns. If the Primary Key is defined using more that one columns, it is known as a Composite Key (or Composite Primary Key). Therefore, a Composite Key in a table does not mean that there are more than one Primary Keys in the table. Instead, a Composite Key uses more than one columns to define a (Single) Primary Key. RAJEEVS@CDAC.IN 20
  • 21. Foreign Key • A Foreign Key is a set of attributes in one relation whose values are required to match one of the values of the primary key of the same or different relation. • There can be more than one foreign key in a given relation. 21RAJEEVS@CDAC.IN Identify a relation in any system/business, define its Attributes, Domain for each attribute and find out Primary, Key, Foreign Keys, Candidate Keys, Super Key in the relation.
  • 22. Foreign Key(s)? create table EMPLOYEE( EmpCode integer(4), Name char(30), Desig char(4), Grade integer(4), JoinDate date, Basic integer(7)), Gender char(1), DeptCode char(4) ) create table DEPT( DeptCode char(4), DeptName char(30), Location char(10) ) 22RAJEEVS@CDAC.IN
  • 23. Integrity Rules Entity Integrity: Implemented through Primary Key “No Attribute participating in the primary key of a relation may accept null values” Guarantees that each tuple will have a unique identity. Referential Integrity: Implemented through Foreign Key “Values of the foreign key (a) must be either null, or (b) if non-null, must match with the primary key value of some tuple of the `parent’ relation. The reference can be to the same relation” *Foreign Key is also know as Reference/Referential key. 23RAJEEVS@CDAC.IN
  • 24. Relational Database Operations • SELECTION: This selects some or all of the records in a table. Through WHERE Clause • PROJECTION: This limits columns from a table. Through SELECT Clause • UNION • INTERSECTION • DIFFERENCE • JOIN • CARTESIAN PRODUCT RAJEEVS@CDAC.IN 24