Download presentation
Presentation is loading. Please wait.
Published byCorey Dickerson Modified over 9 years ago
1
Chapter 3: Relational Model Structure of Relational Databases Normal forms (chap. 7) Reduction of an E-R Schema to Relational (Sect. 2.9) Relational Algebra Tuple Relational Calculus Domain Relational Calculus Extended Relational-Algebra-Operations Modification of the Database Views
2
Relational Model Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. “Legacy systems” in older models E.G., IBM’s IMS E.G., IBM’s IMS
3
Basic Structure Formally, given sets D 1, D 2, …. D n a relation r is a subset of D 1 x D 2 x … x D n. Thus a relation is a set of n-tuples (a 1, a 2, …, a n ) where each a i D i Example: if customer-name = {Jones, Smith, Curry, Lindsay} customer-street = {Main, North, Park} customer-city = {Harrison, Rye, Pittsfield} then r = { (Jones, Main, Harrison), (Smith, North, Rye), (Curry, North, Rye), (Lindsay, Park, Pittsfield)} is a relation over customer-name x customer- street x customer-city
4
Example of a Relation
5
Attribute Types Each attribute of a relation has a name 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 The null value causes complications in the definition of many operations we shall ignore the effect of null values in our main presentation and consider their effect later we shall ignore the effect of null values in our main presentation and consider their effect later
6
Relation Schema A 1, A 2, …, A n are attributes R = (A 1, A 2, …, A n ) is a relation schema E.g. Customer-schema = (customer-name, customer-street, customer-city) r(R) is a relation on the relation schema R E.g.customer (Customer-schema)
7
Relation Instance Relation instance: the current values of a relation that are specified by a table An element t of r is a tuple, represented by a row in a table Jones Smith Curry Lindsay Main North Park Harrison Rye Pittsfield customer-city customer attributes (or columns) tuples (or rows) customer-name customer-steet
8
Relations are Unordered Order of tuples is irrelevant (tuples may be stored in an arbitrary order) E.g. account relation with unordered tuples
9
Database A database consists of multiple relations Information about an enterprise is broken up into parts, with each relation storing one part of the information E.g.: account : information about accounts depositor : information about which customer owns which account customer : stores information about customers Storing all information as a single relation such as bank(account-number, balance, customer-name,..) results in repetition of information (e.g. two customers own an account) repetition of information (e.g. two customers own an account) the need for null values (e.g. represent a customer without an account) the need for null values (e.g. represent a customer without an account) Normalization theory (Chapter 7) deals with how to design relational schemas
10
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) by “possible r” we mean a relation r that could exist in the enterprise we are modeling. by “possible r” we mean a relation r that could exist in the enterprise we are modeling. Example: {customer-name, customer-street} and {customer-name} are both superkeys of Customer, if no two customers can possibly have the same name. Example: {customer-name, customer-street} and {customer-name} are both superkeys of Customer, if no two customers can possibly have the same name. K is a candidate key if K is minimal Example: {customer-name} is a candidate key for Customer, since it is a superkey (assuming no two customers can possibly have the same name), and no subset of it is a superkey. Example: {customer-name} is a candidate key for Customer, since it is a superkey (assuming no two customers can possibly have the same name), and no subset of it is a superkey.
11
Foreign Keys Foreign key: primary key of a relation R that appears as attribute of another relation S. R is called the referencing relation and S the referenced relation Eg: customer_name in depositor relation is a foreign key wrt the customer relation and account_number is a foreign key wrt the account relation
12
The customer Relation
13
The depositor Relation
14
Relational database customer(customer-name,customer-street,customer-city) not null(customer-street, customer-city) account(account-number, branch-name, balance) not null(branch-name, balance) depositor(customer-name, account-number) not null(customer-name, account-number) customer-name: FK(customer) account-number: FK(account)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.