SlideShare uma empresa Scribd logo
1 de 27
Lecture 2
Relational Model and Terminology
Objectives
• In this lecture, you will learn:
– Some relational model terminologies
– The difference between the relation schema and
relational database schema
– The properties of a relation
– Relational keys
– Relational intergrity
– Views and purpose of views in relational database
2
Relational Model Terminology
• An entity is a person, place, event, or
thing/Object for which we intend to collect
data
• Examples:
– University -- Students, Faculty Members, Courses
– Airline -- Pilots, Aircraft, Routes, Suppliers
• A relation is a table with columns and rows.
– Only applies to logical structure of the database,
not the physical structure.
Relational Model Terminology
• Attribute is a named column of a relation.
• Example:
– Student -- Student Number, Name...etc
• Domain is the set of allowable values for one
or more attributes.
Attribute Domain Name Meaning Domain
Definition
Stu_id StudentID ID of a student Character:
Size 10
Relational Model Terminology
• Tuple is a row of a relation.
• Degree is the number of attributes in a relation.
• Cardinality is the number of tuples in a relation.
• Relational Database
– A collection of normalized relations with distinct
relation names.
6
Example of Attribute Domain
7
Entity and Attribute
Alternative Terminology
Attribute
Entity Occurrence
Entity Class
Conceptual data modeling notation
Student File
Id No. Name Faculty Major
1100 Ali FIT SE
1200 Mohamed FIT MIS
1300 Aisha FCM MM
1400 Hawwa FCM MM
1500 Hussain FOE CE
Alternative Terminology
Attribute
Field
Entity Occurrence
Record
Entity Class
File
Conceptual data modeling notation
File Processing Notation
Student File
Id No. Name Faculty Major
1100 Ali FIT SE
1200 Mohamed FIT MIS
1300 Aisha FCM MM
1400 Hawwa FCM MM
1500 Hussain FOE CE
Alternative Terminology
Attribute
Field
Column
Entity Occurrence
Record
Row
Entity Class
File
Table
Conceptual data modeling notation
File Processing Notation
Relational Table Notation
Student File
Id No. Name Faculty Major
1100 Ali FIT SE
1200 Mohamed FIT MIS
1300 Aisha FCM MM
1400 Hawwa FCM MM
1500 Hussain FOE CE
Database Relations
• Relation schema
• Named relation defined by a set of attribute and domain
name pairs.
• Relational database schema
• Set of relation schemas, each with a distinct name.
Relation and Relational Schema
• A relation schema is the name and the list of
attributes of a relation
• Example:
– Grade (studentId, assignmentId, points, dateSubmitted)
Relational Schema
Properties of Relation
• Relation name is distinct from all other relation names
in relational schema.
• Each cell of relation contains exactly one atomic (single)
value.
• Each attribute has a distinct name.
• Values of an attribute are all from the same domain.
• Each tuple is distinct; there are no duplicate tuples.
• Order of attributes has no significance.
• Order of tuples has no significance, theoretically.
Relational Keys
• Super key
– An attribute, or a set of attributes, that uniquely identifies a
tuple within a relation.
• Candidate Key
– Super key (K) such that no proper subset is a super key within
the relation.
• Candidate key, K, for a relation R has two properties
– Uniqueness - in each tuple of R, values of K uniquely identify
that tuple.
– Irreducibility - no proper subset of K has the uniqueness
property
Relational Key
• Super key
– Uniquely identifies each entity
• STU_NUM
• STU_NUM, STU_LNAME
• STU_NUM, STU_LNAME, STU_INIT
• Candidate key
– Minimal super key
• STU_NUM
• STU_LNAME, STU_FNAME, STU_INIT, STU_PHONE
• When a key consists of more than one attribute, it is
called a composite key
Example
• Which attributes of this table can be used as a candidate
key?
• BranchNo and PostalCode can be used as candidate keys.
• City attribute cannot be used as a candidate key, because it
has duplicate values.
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B003 56 Clover Dr London NW10 6EU
Relational Key
• Primary Key
– Candidate key selected to identify tuples uniquely within
relation.
• Alternate Keys
– Candidate keys that are not selected to be primary key.
• Foreign Key
– Attribute, or set of attributes, within one relation that matches
candidate key of some (possibly same) relation
Relational Integrity
• Null
– Represents value for an attribute that is currently unknown or
not applicable for tuple.
– Deals with incomplete or exceptional data.
– Represents the absence of a value and is not the same as zero
or spaces, which are values.
– Example: if a student is absent for the final exam. The final
exam value of that student should be null.
Relational Integrity
• Entity Integrity
– In a base relation, no attribute of a primary key can be null.
• Primary key (BranchNo)
• Cannot insert a tuple in this relation if BranchNo is null.
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B006 56 Clover Dr London NW10 6EU
Relational Integrity
• Entity Integrity
– In a base relation, no attribute of a primary key can
be null.
• Composite primary key (ClientNo, PropertyNo)
• Cannot insert a tuple in this relation if either ClientNo
is null, PropertyNo is null or both ClientNo and
PropertyNo are null.
ClientNo PropertyNo ViewDate Comment
CR56 PA14 24 May 01 Too small
CR76 PG4 20 April 01 Too remote
CR56 PG4 16 May 01
CR62 PA14 14 May 01 No dining room
CR56 PG36 28 April 01
Relational Integrity
• Referential Integrity
– If foreign key exists in a relation, either foreign key value
must match a candidate key value of some tuple in its home
relation or foreign key value must be wholly null.
22
Relational Integrity
BranchNo Street City PostalCode
B005 22 Deer Rd London SW1 4EH
B007 16 Argyll St Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B006 56 Clover Dr London NW10 6EU
staffNo fName lName Position Sex Salary BranchNo
SL21 Jhon White Manager M 30000 B005
SG37 Ann Beech Assistant F 12000 B003
SG14 David Ford Supervisor M 18000 B003
SA9 Mary Howe Assistant F 9000 B007
SG5 Susan Brand Manager F 24000 B003
SL41 Julie Lee Assistant F 9000 B005
Referential Integrity: Example
• BranchNo in the staff relation is a foreign key
targeting the BranchNo attribute in the Branch
relation.
• Not possible to create a staff record with non
existing BrancNo (example with B025)
• But it is possible to create a staff record with a
null branch number to cater for new staff who
has not assigned any branch office.
23
Referential Integrity: Example
• Consider the situation where we have two tables:
Employees and Managers. The Employees table
has a foreign key attribute entitled ManagedBy
which points to the record for that employee’s
manager in the Managers table.
– We may not add a record to the Employees table
unless the ManagedBy attribute points to a valid
record in the Managers table.
– If the primary key for a record in the Managers table
changes, all corresponding records in the Employees
table must be modified using a cascading update.
– If a record in the Managers table is deleted, all
corresponding records in the Employees table must be
deleted using a cascading delete.
24
Views
• Base Relation
– Named relation corresponding to an entity in conceptual schema,
whose tuples are physically stored in database.
• View
– Dynamic result of one or more relational operations operating on
base relations to produce another relation.
– A view is a virtual relation that does not necessarily exists in a
database but can be produced upon request.
– Contents of a view are defined as a query on one or more base
relations.
– Views are dynamic, meaning that changes made to base relations
that affect view attributes are immediately reflected in the view.
Views: Examples
26
Student
StudentID Student Name DOB Mark1 Mark2 Mark3
00001 Mohamed 2/2/1985 56 85 74
00002 Ahmed 3/3/1990 85 45 25
00003 Aisha 4/4/1992 75 95 35
00004 Hawwa 6/6/1989 56 54 87
Query1
StudentID Mark1 Mark2 Mark3
00001 56 85 74
00002 85 45 25
00003 75 95 35
00004 56 54 87
Query2
StudentID Student Name Mark1
00001 Mohamed 56
00002 Ahmed 85
00003 Aisha 75
00004 Hawwa 56
Purpose of Views
• Provides powerful and flexible security mechanism by hiding
parts of database from certain users.
• Permits users to access data in a customized way, so that same
data can be seen by different users in different ways, at the
same time.
• Can simplify complex operations on base relations ( Example:
join).
• A view should be designed to support external model:
– Some members of the staff should be able to see staff tuples
without the salary attribute.
– Attributes may be renamed or the order of attributes changed.
– Some members of the staff should see only a specific records.

Mais conteúdo relacionado

Semelhante a Lecture 2 - Relational Model and Terminology.pptx

Semelhante a Lecture 2 - Relational Model and Terminology.pptx (20)

RDBMS Model
RDBMS ModelRDBMS Model
RDBMS Model
 
18306_lec-2 (1).ppt
18306_lec-2 (1).ppt18306_lec-2 (1).ppt
18306_lec-2 (1).ppt
 
Relational model
Relational modelRelational model
Relational model
 
19IS305_U2_LP4_LM4-22-23.pdf
19IS305_U2_LP4_LM4-22-23.pdf19IS305_U2_LP4_LM4-22-23.pdf
19IS305_U2_LP4_LM4-22-23.pdf
 
Relational Model
Relational ModelRelational Model
Relational Model
 
The Relational Model
The Relational ModelThe Relational Model
The Relational Model
 
entityrelationshipmodel.pptx
entityrelationshipmodel.pptxentityrelationshipmodel.pptx
entityrelationshipmodel.pptx
 
entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
 
Data Models.pptx
Data Models.pptxData Models.pptx
Data Models.pptx
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
Lecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptxLecture-2 - Relational Model.pptx
Lecture-2 - Relational Model.pptx
 
ERD(2).ppt
ERD(2).pptERD(2).ppt
ERD(2).ppt
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 
Revision ch 3
Revision ch 3Revision ch 3
Revision ch 3
 
7.relational model
7.relational model7.relational model
7.relational model
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
NMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.pptNMEC RD_UNIT 1.ppt
NMEC RD_UNIT 1.ppt
 
ER_model
ER_modelER_model
ER_model
 
ER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMSER Modeling and Introduction to RDBMS
ER Modeling and Introduction to RDBMS
 

Último

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Último (20)

Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Lecture 2 - Relational Model and Terminology.pptx

  • 1. Lecture 2 Relational Model and Terminology
  • 2. Objectives • In this lecture, you will learn: – Some relational model terminologies – The difference between the relation schema and relational database schema – The properties of a relation – Relational keys – Relational intergrity – Views and purpose of views in relational database 2
  • 3. Relational Model Terminology • An entity is a person, place, event, or thing/Object for which we intend to collect data • Examples: – University -- Students, Faculty Members, Courses – Airline -- Pilots, Aircraft, Routes, Suppliers • A relation is a table with columns and rows. – Only applies to logical structure of the database, not the physical structure.
  • 4. Relational Model Terminology • Attribute is a named column of a relation. • Example: – Student -- Student Number, Name...etc • Domain is the set of allowable values for one or more attributes. Attribute Domain Name Meaning Domain Definition Stu_id StudentID ID of a student Character: Size 10
  • 5. Relational Model Terminology • Tuple is a row of a relation. • Degree is the number of attributes in a relation. • Cardinality is the number of tuples in a relation. • Relational Database – A collection of normalized relations with distinct relation names.
  • 8. Alternative Terminology Attribute Entity Occurrence Entity Class Conceptual data modeling notation Student File Id No. Name Faculty Major 1100 Ali FIT SE 1200 Mohamed FIT MIS 1300 Aisha FCM MM 1400 Hawwa FCM MM 1500 Hussain FOE CE
  • 9. Alternative Terminology Attribute Field Entity Occurrence Record Entity Class File Conceptual data modeling notation File Processing Notation Student File Id No. Name Faculty Major 1100 Ali FIT SE 1200 Mohamed FIT MIS 1300 Aisha FCM MM 1400 Hawwa FCM MM 1500 Hussain FOE CE
  • 10. Alternative Terminology Attribute Field Column Entity Occurrence Record Row Entity Class File Table Conceptual data modeling notation File Processing Notation Relational Table Notation Student File Id No. Name Faculty Major 1100 Ali FIT SE 1200 Mohamed FIT MIS 1300 Aisha FCM MM 1400 Hawwa FCM MM 1500 Hussain FOE CE
  • 11. Database Relations • Relation schema • Named relation defined by a set of attribute and domain name pairs. • Relational database schema • Set of relation schemas, each with a distinct name.
  • 12. Relation and Relational Schema • A relation schema is the name and the list of attributes of a relation • Example: – Grade (studentId, assignmentId, points, dateSubmitted) Relational Schema
  • 13. Properties of Relation • Relation name is distinct from all other relation names in relational schema. • Each cell of relation contains exactly one atomic (single) value. • Each attribute has a distinct name. • Values of an attribute are all from the same domain. • Each tuple is distinct; there are no duplicate tuples. • Order of attributes has no significance. • Order of tuples has no significance, theoretically.
  • 14. Relational Keys • Super key – An attribute, or a set of attributes, that uniquely identifies a tuple within a relation. • Candidate Key – Super key (K) such that no proper subset is a super key within the relation. • Candidate key, K, for a relation R has two properties – Uniqueness - in each tuple of R, values of K uniquely identify that tuple. – Irreducibility - no proper subset of K has the uniqueness property
  • 15. Relational Key • Super key – Uniquely identifies each entity • STU_NUM • STU_NUM, STU_LNAME • STU_NUM, STU_LNAME, STU_INIT • Candidate key – Minimal super key • STU_NUM • STU_LNAME, STU_FNAME, STU_INIT, STU_PHONE • When a key consists of more than one attribute, it is called a composite key
  • 16. Example • Which attributes of this table can be used as a candidate key? • BranchNo and PostalCode can be used as candidate keys. • City attribute cannot be used as a candidate key, because it has duplicate values. BranchNo Street City PostalCode B005 22 Deer Rd London SW1 4EH B007 16 Argyll St Aberdeen AB2 3SU B003 163 Main St Glasgow G11 9QX B004 32 Manse Rd Bristol BS99 1NZ B003 56 Clover Dr London NW10 6EU
  • 17. Relational Key • Primary Key – Candidate key selected to identify tuples uniquely within relation. • Alternate Keys – Candidate keys that are not selected to be primary key. • Foreign Key – Attribute, or set of attributes, within one relation that matches candidate key of some (possibly same) relation
  • 18. Relational Integrity • Null – Represents value for an attribute that is currently unknown or not applicable for tuple. – Deals with incomplete or exceptional data. – Represents the absence of a value and is not the same as zero or spaces, which are values. – Example: if a student is absent for the final exam. The final exam value of that student should be null.
  • 19. Relational Integrity • Entity Integrity – In a base relation, no attribute of a primary key can be null. • Primary key (BranchNo) • Cannot insert a tuple in this relation if BranchNo is null. BranchNo Street City PostalCode B005 22 Deer Rd London SW1 4EH B007 16 Argyll St Aberdeen AB2 3SU B003 163 Main St Glasgow G11 9QX B004 32 Manse Rd Bristol BS99 1NZ B006 56 Clover Dr London NW10 6EU
  • 20. Relational Integrity • Entity Integrity – In a base relation, no attribute of a primary key can be null. • Composite primary key (ClientNo, PropertyNo) • Cannot insert a tuple in this relation if either ClientNo is null, PropertyNo is null or both ClientNo and PropertyNo are null. ClientNo PropertyNo ViewDate Comment CR56 PA14 24 May 01 Too small CR76 PG4 20 April 01 Too remote CR56 PG4 16 May 01 CR62 PA14 14 May 01 No dining room CR56 PG36 28 April 01
  • 21. Relational Integrity • Referential Integrity – If foreign key exists in a relation, either foreign key value must match a candidate key value of some tuple in its home relation or foreign key value must be wholly null.
  • 22. 22 Relational Integrity BranchNo Street City PostalCode B005 22 Deer Rd London SW1 4EH B007 16 Argyll St Aberdeen AB2 3SU B003 163 Main St Glasgow G11 9QX B004 32 Manse Rd Bristol BS99 1NZ B006 56 Clover Dr London NW10 6EU staffNo fName lName Position Sex Salary BranchNo SL21 Jhon White Manager M 30000 B005 SG37 Ann Beech Assistant F 12000 B003 SG14 David Ford Supervisor M 18000 B003 SA9 Mary Howe Assistant F 9000 B007 SG5 Susan Brand Manager F 24000 B003 SL41 Julie Lee Assistant F 9000 B005
  • 23. Referential Integrity: Example • BranchNo in the staff relation is a foreign key targeting the BranchNo attribute in the Branch relation. • Not possible to create a staff record with non existing BrancNo (example with B025) • But it is possible to create a staff record with a null branch number to cater for new staff who has not assigned any branch office. 23
  • 24. Referential Integrity: Example • Consider the situation where we have two tables: Employees and Managers. The Employees table has a foreign key attribute entitled ManagedBy which points to the record for that employee’s manager in the Managers table. – We may not add a record to the Employees table unless the ManagedBy attribute points to a valid record in the Managers table. – If the primary key for a record in the Managers table changes, all corresponding records in the Employees table must be modified using a cascading update. – If a record in the Managers table is deleted, all corresponding records in the Employees table must be deleted using a cascading delete. 24
  • 25. Views • Base Relation – Named relation corresponding to an entity in conceptual schema, whose tuples are physically stored in database. • View – Dynamic result of one or more relational operations operating on base relations to produce another relation. – A view is a virtual relation that does not necessarily exists in a database but can be produced upon request. – Contents of a view are defined as a query on one or more base relations. – Views are dynamic, meaning that changes made to base relations that affect view attributes are immediately reflected in the view.
  • 26. Views: Examples 26 Student StudentID Student Name DOB Mark1 Mark2 Mark3 00001 Mohamed 2/2/1985 56 85 74 00002 Ahmed 3/3/1990 85 45 25 00003 Aisha 4/4/1992 75 95 35 00004 Hawwa 6/6/1989 56 54 87 Query1 StudentID Mark1 Mark2 Mark3 00001 56 85 74 00002 85 45 25 00003 75 95 35 00004 56 54 87 Query2 StudentID Student Name Mark1 00001 Mohamed 56 00002 Ahmed 85 00003 Aisha 75 00004 Hawwa 56
  • 27. Purpose of Views • Provides powerful and flexible security mechanism by hiding parts of database from certain users. • Permits users to access data in a customized way, so that same data can be seen by different users in different ways, at the same time. • Can simplify complex operations on base relations ( Example: join). • A view should be designed to support external model: – Some members of the staff should be able to see staff tuples without the salary attribute. – Attributes may be renamed or the order of attributes changed. – Some members of the staff should see only a specific records.

Notas do Editor

  1. LOGICAL STRUCTURE OF DATABASE Logical structure mainly consists of tablespace, segments, extents, and oracle data blocks TABLESPACE Each database is logically divided into one or more tablespaces. One or more datafiles are explicitly created for each tablespace to physically store the data of all logical structures in a tablespace. The combined size of the datafiles in a tablespace is the total storage capacity of the tablespace. SEGMENT A segment is a set of extents allocated for a certain logical structure. The segments can be of one of following type data segment,index segment,temporary segment,rollback segment. EXTENT The next level of logical database space is an extent. An extent is a specific number of contiguous data blocks, obtained in a single allocation, used to store a specific type of information. ORACLE DATABLOCKS At the finest level of granularity, Oracle database data is stored in data blocks. One data block corresponds to a specific number of bytes of physical database space on disk. The standard block size is specified by the DB_BLOCK_SIZE initialization parameter. In addition, you can specify up to five other block sizes.
  2. Definition: Referential integrity is a database concept that ensures that relationships between tables remain consistent. When one table has a foreign key to another table, the concept of referential integrity states that you may not add a record to the table that contains the foreign key unless there is a corresponding record in the linked table. It also includes the techniques known as cascading update and cascading delete, which ensure that changes made to the linked table are reflected in the primary table. Consider the situation where we have two tables: Employees and Managers. The Employees table has a foreign key attribute entitled ManagedBy which points to the record for that employee’s manager in the Managers table. Referential integrity enforces the following three rules: We may not add a record to the Employees table unless the ManagedBy attribute poi nts to a valid record in the Managers table. If the primary key for a record in the Managers table changes, all corresponding records in the Employees table must be modified using a cascading update. If a record in the Managers table is deleted, all corresponding records in the Employees table must be deleted using a cascading delete.