Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science.

Similar presentations


Presentation on theme: "The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science."— Presentation transcript:

1 The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science

2 History of Relational Model First proposed by a E.F. Codd in 1970. Codd proposed the Relational model in 1970.  “ A relational model of data for large shared data banks.” He linked the representation of data with that of mathematical sets. First research started at IBM’s San Jose Research Laboratory. Prototype was called System R. Commercial RDBMS’s started to appear in late 1970’s and early 1980’s. Most well known is Oracle.

3 Dr. Edgar F. Codd (1923-2003) Codd completed his PhD at the University of Michigan in 1963, and presented a thesis on the topic of a self- reproducing computer consisting of a large number of simple identical cells, each of which interacts in a uniform manner with its four immediate neighbors. Codd reported this work in a book entitled Cellular Automata published by Academic Press in 1968. Codd completed his PhD at the University of Michigan in 1963, and presented a thesis on the topic of a self- reproducing computer consisting of a large number of simple identical cells, each of which interacts in a uniform manner with its four immediate neighbors. Codd reported this work in a book entitled Cellular Automata published by Academic Press in 1968.Cellular AutomataCellular Automata

4 Edgar Codd The relational model devised by Codd was explored during the 1970s, and commercial relational database products began to emerge in the 1980s, originally for mainframe systems and later for microcomputers. Edgar Codd first wrote about the concept of relational databases in his paper "A Relational Model of Data for Large Shared Data Banks" in 1970. He was using the term "relation" in the strict mathematical sense of a table with a few special properties. Thus Codd was describing a system where all of the database - data, structure, rules - is housed in simple tables of rows and columns. The relational model devised by Codd was explored during the 1970s, and commercial relational database products began to emerge in the 1980s, originally for mainframe systems and later for microcomputers. Edgar Codd first wrote about the concept of relational databases in his paper "A Relational Model of Data for Large Shared Data Banks" in 1970. He was using the term "relation" in the strict mathematical sense of a table with a few special properties. Thus Codd was describing a system where all of the database - data, structure, rules - is housed in simple tables of rows and columns.relational modelrelational databases"relation"database relational modelrelational databases"relation"database

5 Edgar Codd While this may seem obvious to us today, it was by no means obvious in 1970. Codd went on to define relational databases more completely where he laid out twelve principles of relational databases in 1974. His most recent work in 1990, expands the list to 333 requirements.(Codd 90) Normalization for relational databases was introduced by Dr. E. F. Codd back in 1970 when he wrote his original paper. The concept has since been expounded upon by other experts in the field. While this may seem obvious to us today, it was by no means obvious in 1970. Codd went on to define relational databases more completely where he laid out twelve principles of relational databases in 1974. His most recent work in 1990, expands the list to 333 requirements.(Codd 90) Normalization for relational databases was introduced by Dr. E. F. Codd back in 1970 when he wrote his original paper. The concept has since been expounded upon by other experts in the field.Codd 90 NormalizationCodd 90 Normalization Read his obituary http://www.intosaiitaudit.org/intoit_articles/18p60top62.pdf Read his obituary http://www.intosaiitaudit.org/intoit_articles/18p60top62.pdf

6 Read: http://www.mercurynews.com/mld/mercurynews/ news/local/5676133.htm?1c IBM database developer dead at 79 IBM database developer dead at 79 `RELATIONAL' MODEL IS BASIS OF TODAY'S TRANSACTIONS By Lisa M. Krieger Mercury News `RELATIONAL' MODEL IS BASIS OF TODAY'S TRANSACTIONS By Lisa M. Krieger Mercury News Edgar F. Codd, an IBM computer pioneer who created the ``relational database model'' that underlies a $7 billion industry of storing the world's online business data, died of heart failure at home Friday in Williams Island, Fla. He was 79. Edgar F. Codd, an IBM computer pioneer who created the ``relational database model'' that underlies a $7 billion industry of storing the world's online business data, died of heart failure at home Friday in Williams Island, Fla. He was 79. Bank accounts, credit cards, stock trading, travel reservations, online auctions and innumerable other now-routine data transactions all rely on Codd's model, based on highly abstract and complex mathematical theory. Bank accounts, credit cards, stock trading, travel reservations, online auctions and innumerable other now-routine data transactions all rely on Codd's model, based on highly abstract and complex mathematical theory. Before Codd's landmark research paper in 1970, it was possible to store lots of information -- but analyzing it was difficult, requiring lines and lines of code for even simple tasks. Before Codd's landmark research paper in 1970, it was possible to store lots of information -- but analyzing it was difficult, requiring lines and lines of code for even simple tasks.

7 Codd ’ s Original Paper “ A Relational Model of Data for Large Shared Data Banks ” “ A Relational Model of Data for Large Shared Data Banks ” Communications of the ACM, Volume 13, Number 6, June 1970 Communications of the ACM, Volume 13, Number 6, June 1970 Lower level (basement) of the new Martin Luther King, Jr. Library Lower level (basement) of the new Martin Luther King, Jr. Library Get to roll the shelves apart to access journals. Get to roll the shelves apart to access journals.

8 Codd ’ s Reasons Data independence from database implementation such as machine representation Data independence from database implementation such as machine representation Natural structure of data Natural structure of data Can be analyzed mathematically (Codd was a mathematician by training) Can be analyzed mathematically (Codd was a mathematician by training)

9 Alternative: Network Model Charles A. Bachman 1973 ACM Turing Award Lecture “ The Programmer as Navigator ” Charles A. Bachman 1973 ACM Turing Award Lecture “ The Programmer as Navigator ” Communications of the ACM, Volume 16, Number 11, November 1973, pp. 653-657 Communications of the ACM, Volume 16, Number 11, November 1973, pp. 653-657

10

11 INTRODUCTION The relational model is the most used data model for commercial data-processing because it is simple to use and to maintain. A relational data model is based on a collection of tables. The user of the database system may query these tables, insert new tuples, and update (modify) tuples. There are several languages for expressing these operations.

12 Data Models · Codd suggests that any data model has three components: the data structures; the data structures; the integrity constraints; the integrity constraints; the data manipulation operators. the data manipulation operators.

13

14

15 Relational Data Structure EMPLOYEE Emp# Name Emp Sex Mgr Emp# E1 JonesMaleE65 E6 SmithMaleE28 E28Jones Female- Relation Attribute Heading Body Female Male Gender Domain

16 Basic Structure account-numberbranch-namebalance A-101Downtown500 A-102Perryridge400 A-201Brighton900 A-215Mianus700 The account table below represents a relation in the relational model. The three columns titles are the attributes and their domains. Each row is called a tuple. An account is a subset of the set of all possible tuples.

17 The Domain Emp# E1 E2 E3 Name Red Brown Black Mgr# - E1 E1, E2, E3,E4 Red, Brown Black, Blue Attributes Domains Employee Person Name Emp#

18

19

20 Seven Characteristics of a relation The name of the relation is different from all others. Each cell of the relation contains only one value Each attribute (or field) has a name that is distinct. All the values of a particular attribute are from the same domain. The order of the attributes makes no difference. There are no duplicate tuples The order of the tuples makes no difference.

21 Example of the Student table. Primary Key

22 Other terms... Cardinality = Number of rows Cardinality = Number of rows Degree = Number of columns Degree = Number of columns Cardinality = 6 Degree = 5

23

24

25

26

27

28

29

30 Database Schema Database Schema is the logical design of the database Database Schema is the logical design of the database Database instance is a snapshot of the data in the DB at a given instance in time Database instance is a snapshot of the data in the DB at a given instance in time Relation instance is the programming language notion of a value of a variable Relation instance is the programming language notion of a value of a variable

31 Database Schema Relation schema consists of a list of attributes and their corresponding domain. As a convention, uppercase letter are used so Account-schema=(account-number, branch- name, balance) This means that account is a relation on Account-schema by account(Account-schema)

32 Database Schema Relation instance is the set of values of a relation at a specific moment in time. This values may change in time causing a change in the relation as it is updated.

33 The Relational Data Model · DATA STRUCTURES - domain, attribute, relation, tuple, primary key, degree, cardinality. INTEGRITY CONSTRAINTS - entity integrity and referential integrity. INTEGRITY CONSTRAINTS - entity integrity and referential integrity. DATA MANIPULATION OPERATIONS - defined through relational algebra and equivalent relational calculus. DATA MANIPULATION OPERATIONS - defined through relational algebra and equivalent relational calculus.

34 Keys Superkey is a set of one or more attributes that allow us to identify uniquely an entity in the entity set. Superkey is a set of one or more attributes that allow us to identify uniquely an entity in the entity set. Candidate Key are minimal superkey in an entity, one of those keys is selected to be the primary key Candidate Key are minimal superkey in an entity, one of those keys is selected to be the primary key Primary Key is a candidate key that is chosen to identify entities within an entity set Primary Key is a candidate key that is chosen to identify entities within an entity set Foreign Key is a primary key of another relation schema Foreign Key is a primary key of another relation schema

35 Keys If K of R is a superkey for R, then the relation r(R) does not have two tuples with the same value. So if t1 and t 2 are in r t 1 = t 2

36 Find Candidate Keys R(A, B, C, D) R(A, B, C, D) 12 3 4 1 1 3 4 32 1 4 4 1 2 3 {A, B} {A, C} {A, D} {B, C} {B, D} {C, D} X {A,C,D} {B, C, D}  XX  X  = okay  = not okay

37 How to determine keys Strong entity set: the entity primary key becomes the relation primary key Strong entity set: the entity primary key becomes the relation primary key Weak entity set: the primary key of the relation is the union of the strong entity set primary key and the discriminator Weak entity set: the primary key of the relation is the union of the strong entity set primary key and the discriminator Relation set: the union of the primary keys of the related entity sets becomes a superkey of the relation Relation set: the union of the primary keys of the related entity sets becomes a superkey of the relation

38 How to determine keys Combined tables: in a many-to-one, the primary key of the many becomes the relation primary key. In a one-to-one either primary key can be used Combined tables: in a many-to-one, the primary key of the many becomes the relation primary key. In a one-to-one either primary key can be used Multivalued attributes: the entity primary key becomes the primary key Multivalued attributes: the entity primary key becomes the primary key

39 account-number branch-name balance Schema Diagram branch-name branch-city assets customer-name loan-number customer-name customer-street customer-city customer-name account-number loan-number branch-name amount account depositorcustomer branchloan borrower dependency relation shade indicates primary key A database schema with primary and foreign key dependencies primary

40 Entity Integrity · No component of the Primary Key of a base relation is allowed to accept nulls. Surname Red Black Red Black Given Name John Fred Salary $40,000 $50,000 $60,000 $70,000

41

42

43

44

45

46

47

48 Foreign Key · A foreign key is an attribute or attribute combination of one relation R2 whose values are required to match those of the primary key of relation R1 where R1 and R2 are not necessarily distinct. Note that a foreign key and the corresponding primary key should be defined on the same domain(s). Emp# e1 e2 e3 ename red blue brown Dept d1 d2 d3 Worksfordept d1 d2 Dname Pay Tax Art Employee Dept Foreign key

49 Referential Integrity If base relation R2 includes a foreign key FK matching the primary key PK of some base relation R1 then every value of FK in R2 must either (a) be equal to the value of PK in some tuple of R1, or (b) be wholly null. Note that PK and FK may comprise more than one attribute and that R1 and R2 are not necessarily distinct. ( Stated more simply a foreign key should be a valid primary key value or null.)

50 Foreign Key Rules For each foreign key three rules need to be answered: Can the foreign key accept nulls ? What should happen on an attempt to delete the target of a foreign key reference? What should happen on an attempt to update the target of a foreign key reference ? Emp# e1 e2 e3 ename red blue brown Dept d1 d2 d3 Worksfordept d1 d2 Dname Pay Tax Art EmployeeDept

51 Foreign Key Rules When should foreign key rules be checked ? Dept (Dept#, Dname, Budget) Emp (Emp#, Ename, Salary, WorksforDept#) WorksforDept# References Dept delete cascades, update cascades WorksforDept# References Dept delete cascades, update cascades Depend (Emp#, Dependname, Date-of-birth) Emp# references Emp delete cascades, update cascades Emp# references Emp delete cascades, update cascades

52 Example of the Class table. Primary Key

53 Foreign key example

54 Relational instances in the Student relation The content of the table (a grouping of rows) are called relational instances The content of the table (a grouping of rows) are called relational instances These instances are unordered, and no two rows can be exactly alike These instances are unordered, and no two rows can be exactly alike A relational instance

55 Integrity Constraints All DBMS ’ must have some form of ICs to prevent invalid data from being entered. All DBMS ’ must have some form of ICs to prevent invalid data from being entered. Domain constraints specify the set of values which may be used for each field. Domain constraints specify the set of values which may be used for each field. Other constraints, such as key or tuple, may limit which values from the domain can be used for a given field in a given instance. Other constraints, such as key or tuple, may limit which values from the domain can be used for a given field in a given instance. Key constraints require that each set of fields in the key be unique for each entry. Key constraints require that each set of fields in the key be unique for each entry.

56 Enforcing Integrity Constraints Each DBMS should have means to resolve invlaid entries such as: Each DBMS should have means to resolve invlaid entries such as: What happens if an entry that duplicates a key entry is entered? What happens if an entry that duplicates a key entry is entered? What should be done if an entry of a foreign key is deleted? What should be done if an entry of a foreign key is deleted? A foreign key is a key where at least one field depends on a field from a different table. A foreign key is a key where at least one field depends on a field from a different table. What happens when an invalid entry is entered? What happens when an invalid entry is entered?

57 Relation schema Associated with each attribute is a set of values, called a domain, that can be assigned to the entry of a tuple corresponding to the attribute. Associated with each attribute is a set of values, called a domain, that can be assigned to the entry of a tuple corresponding to the attribute. A relation schema is a set of attributes. A relation schema is a set of attributes. Example EMP = { Name, SSN, DeptName, Salary, Birthdate } Example EMP = { Name, SSN, DeptName, Salary, Birthdate } Convention EMP(Name,SSN,DeptName,Salary,Birthdate) Convention EMP(Name,SSN,DeptName,Salary,Birthdate)

58 IBM Relational Products DB2 MVS/370 MVS/XA SQL/DS VM/CMS DOS/VSE QMF front-end to DB2 and SQL/DS CSP application development tool Numerous other RDBMS ORACLE (SQL*Forms) INGRES from ASK Corp. (OSL,ABF) AIM/RDB from Fujitsu INFORMIX VAXSQL/Rdb from DEC NonStop SQL from Tandem Relational DBMS Products Microcomputer versions ORACLE INGRES dBase IV microSQL practically all micro DBMS

59 The relational model is based on set operations. Tables are sets of rows. The actual storage structure is hidden from the user. The relational model is just concerned with a logical view of the data, not the physical view. There are no pointers for the user to worry about. The only data are explicit values in tables. All data values in the cells of tables are Atomic (also known as Scalar). Exactly one data value and not a set or a repeating group is allowed in each cell. Relational databases are the most widely used in the world ( 90+%.) A mathematical viewpoint helped to shape a database industry. Future? Possibly Object Oriented Database model.

60 Query Languages Users use query languages to request information from the database SQL is the most spread. Database uses two types of query languages: Procedural language: the user instructs the system to perform a sequence of operations on the database Nonprocedural language: the user describes the desired information without giving a specific procedure for obtain the information


Download ppt "The Relational Model 1 Prof. Sin-Min Lee Department of Mathematics and Computer Science Prof. Sin-Min Lee Department of Computer Science."

Similar presentations


Ads by Google