Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model.

Similar presentations


Presentation on theme: "CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model."— Presentation transcript:

1 CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model

2 CS370 Spring 2007 Database DEPTNO DNAME LOC 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON DEPTNO DNAME LOC 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON Table Name: DEPT EMPNO ENAME JOB DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 EMPNO ENAME JOB DEPTNO 7839 KING PRESIDENT 10 7698 BLAKE MANAGER 30 7782 CLARK MANAGER 10 7566 JONES MANAGER 20 Table Name: EMP A relational database is a collection of relations or two-dimensional tables. A relational database is a collection of relations or two-dimensional tables. Definition of Relational Database

3 CS370 Spring 2007  A relational database is a collection of data items organized as a set of formally-described tables from organized as a set of formally-described tables from which data can be accessed or reassembled in many which data can be accessed or reassembled in many different ways without having to reorganize the database different ways without having to reorganize the database tables. tables.  The relational database was invented by E. F. Codd at IBM in 1970. Relational Database

4 CS370 Spring 2007  Each table (which is sometimes called a relation) contains one or more data categories in columns.  Each row contains a unique instance of data for the categories defined by the columns.  A relational database is a set of tables containing data fitted into predefined categories. fitted into predefined categories. Relational Database

5 CS370 Spring 2007  A relation is a table with columns and rows. Only applies to logical structure of the database, not the physical structure. - Attribute is a named column of a relation. - Domain is a set of allowable values for one or more attributes. - Tuple is a row of a relation. - Tuple is a row of a relation. - Degree is a number of attributes in a relation. - Cardinality is a number of tuples in a relation.  Relational Database is a collection of normalized relations. Relational Model Terminology

6 CS370 Spring 2007 Table - Stores data about a particular topic or subject - Stores data about a particular topic or subject - The basic element in any database - The basic element in any database Organized in Organized in - Rows represent the records in a database - Rows represent the records in a database - Columns represents the fields in a database - Columns represents the fields in a database - First Row represents the field names - First Row represents the field names Relational Model Terminology

7 CS370 Spring 2007 Attributes/Columns (collectively as a schema) Tuples/Rows Relation Name/Table Name An ExampleRelation

8 CS370 Spring 2007 1) the entries in the table are single-valued 2) each column has a distinct name (attribute name) 3) all values in a column are values of the same attribute 4) the order of the columns is unimportant 5) each row is distinct 6) the order of the rows is unimportant Normalized Relation - A Structure that satisfies all of these properties. - A two-dimensional table with the following properties: Relation

9 CS370 Spring 2007 Example of an “Un-Normalized" relation: Example of an “Un-Normalized" relation: - A relational database is a collection of relations. - A relational database is a collection of relations. STUDIDNAMECOURSEGRADECOURSEAPT# BS23 M. Ali AccessAAccess12  Rows are called tuples  columns are called attributes

10 CS370 Spring 2007 Alternative Terminology for Relational Model

11 CS370 Spring 2007  Relation, table, file  Attribute, column, field  Tuple, row, record  A two-dimensional table consisting of columns and rows; created from the entities of the object model. from the entities of the object model.  The columns of the table, usually defined from the attributes of the object model. of the object model.  The rows of the table; derived from the entity occurrences of the object model. of the object model. Relation

12 CS370 Spring 2007 - A key is an attribute that appears in a database "record" (a table row) that is used to distinguish that entity instance, (a table row) that is used to distinguish that entity instance, meaning that particular row in the table. meaning that particular row in the table. - A key is an identifying property of a model and/or a database. Keys are a way to associate tuples in different relations (i.e., Keys are a way to associate tuples in different relations (i.e., primary, candidate, foreign). primary, candidate, foreign). Key

13 CS370 Spring 2007 A key on FLIGHT# in FLIGHT-SCHEDULE will force all FLIGHT# ’ s to be unique in FLIGHT-SCHEDULE Consider the following keys on DEPT-AIRPORT: Keys (or identifiers) are uniqueness constraints FLIGHT#AIRPORT-CODEFLIGHT#AIRPORT-CODEFLIGHT#AIRPORT-CODEFLIGHT#AIRPORT-CODE DEPT-AIRPORT FLIGHT#AIRPORT-CODE 101atl 912cph 545lax 242bos FLIGHT#AIRLINEWEEKDAYPRICE FLIGHT-SCHEDULE 101deltamo156 545americanwe110 912scandinavianfr450 242usairmo231 Keys and Identifiers

14 CS370 Spring 2007 - The primary key is important since it is the sole identifier for the tuples in a relation. for the tuples in a relation. - Any tuple in a database may be identified by specifying relation name,primary key and its value. relation name,primary key and its value. - A primary key is composed of one column (simple primary key) or a combination of columns (composite primary keys) key) or a combination of columns (composite primary keys) that provide this unique identification. that provide this unique identification. Primary Key

15 CS370 Spring 2007 The relational data model therefore imposes The relational data model therefore imposes the following two integrity constraints: the following two integrity constraints: (a)No component of a primary key value can be null. (b) Attempts to change the value of a primary key must be carefully controlled. must be carefully controlled. Primary Key

16 CS370 Spring 2007 - Candidate keys can also be simple or composite. Usually, one candidate key is designated as a primary Usually, one candidate key is designated as a primary key, while the others may be called alternate keys. key, while the others may be called alternate keys. - A candidate key is a unique identifier that might be considered when choosing the primary key of a considered when choosing the primary key of a relation. relation. Candidate Key

17 CS370 Spring 2007 ELEMENTS E_NAMEE_ATOMIC_NOE_SYMBOL LEAD Pb 32 HYDROGEN H 1 HELEAM He 2 SODIEM Na 11 PKCKAK

18 CS370 Spring 2007 -- If a foreign key F in relation R matches the primary key P of relation S than every value of F must either be equal to a value of P or be wholly null. -- You can logically relate data from multiple table using foreign key (FK). Foreign Key

19 CS370 Spring 2007

20 S#SNAMESTATUS S# CITY S1 SMITH20 LONDON S2 ALI10 LAHORE S3 ADAMS20 PARIS CITYWEIGHT#COLORP# P1 GREEN12 LONDON P2 RED10 LAHORE P3 BLUE14 PARIS P#QTY S1 P1 300 S2 P2259 S3 P3 400 SUPPLIERS PARTS Suppliers – and – Parts Database S_P PK


Download ppt "CS370 Spring 2007 CS 370 Database Systems Lecture 7 The Relational model."

Similar presentations


Ads by Google