Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model.

Similar presentations


Presentation on theme: "Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model."— Presentation transcript:

1 Chapter 4 Rational data model

2 Chapter 5 Rational data model Chapter 4 Rational data model

3 Contents Relational Model Concepts Relational Model Constraints and Relational Database Schemas

4

5 The things you should know… The relational Model of Data is based on the concept of a Relation. The basic principle of relational database is proposed by E.F.Codd in 1970. The first RDBMS production is System R The most popular RDBMS DB2, Oracle, Ingres, Sybase, Informix,…

6 Informal Definitions RELATION: A table of values  A relation may be thought of as a set of rows.  Each row represents a fact that corresponds to a real- world entity or relationship.  Each row has a value of an item or set of items that uniquely identifies that row in the table.  Each column typically is called by its column name or column header or attribute name.

7 Informal Definitions Key of a Relation:  Each row has a value of a data item (or set of items) that uniquely identifies that row in the table Called the key  In the STUDENT table, SSN is the key  Sometimes row-ids or sequential numbers are assigned as keys to identify the rows in a table Called artificial key

8 Example - Figure 5.1

9 Basic of the Relational Model The relational model gives us a single way to represent data: as a two- dimensional table called a relation.

10 Attributes ( 属性 )  Attributes of a relation serve us as names for the columns of the relation.  Usually, the attributes describes the meaning of entites in the column below.

11 Schemas (模式)  The name of a relation and the set of attributes for a relation is called the schema for that relation.  We show the schema for the relation with the relation name followed by a parenthesized list of its attributes.

12 Tuples (元组)  The rows of a relation, other than the header row containing the attributes, are called tuple. For example:  Relations, however, are sets of tuples, and it is impossible for a tuple to appear more than once in a given relation.

13 Domains (域)  The relational model requires that each component of each tuple be atomic; that is, it must be of some elementary type such as integers or string.  Each attributes of a relation has particular elementary type, thus domain is decided.

14 Formal Definitions A domain has a logical definition. Example: “USA_phone_numbers” are the set of 10 digit phone numbers valid in the U.S. A domain also has a data-type or a format defined for it.  For example, the USA_phone_numbers may have a format: (ddd)-ddd-dddd where each d is a decimal digit.  Dates have various formats such as month, date, year or yyyy-mm-dd, or dd mm,yyyy etc.

15 Equivalent Representations of a Relation  The attributes of the relation can be reordered without change the relation.

16 Relation Instance (关系实例)  A relation about movies is not static; rather, relations change over time.  It is not common for the schema of a relation to change.  We shall call a set of tuples for a given relation an instance of that relation.

17 DEFINITION SUMMARY Informal TermsFormal Terms TableRelation ColumnAttribute/Domain RowTuple Values in a columnDomain Table DefinitionSchema of a Relation Populated TableExtension

18 An Example of Relation Instance Relation: Person (Name, Address, Telephone) Relation Instance: NameAddressTelephone Bob123 Main St555-1234 Bob128 Main St555-1235 Pat123 Main St555-1235 Harry456 Main St555-2221 Sally456 Main St555-2221 Sally456 Main St555-2223 Pat12 State St555-1235

19 More … Relation (Instance) = a set of tuples Database = collection of relations Relation schema = relation name + attributes  Example: Movies (title, year, length, fileType) Database schema = a set of all relation schemas  Movies(Title, Year, Length, FileType)  Star(Name, Age)  Studio(StudioName, Addr)

20 Name Addr Tel N1 A1 T1 N2 A2 T2 N3 A3 T3 N4 T4 N5 T5 T6 T7 Name Addr Tel N1 A1 T1 N1 A1 T2 N1 A1 T3. N1 A1 T7 N1 A2 T1 N1 A3 T1 N2 A1 T1 Tuple Domai n Component Attribute

21 Characteristics of Relations Ordering of tuples in a relation r(R):  The tuples are not considered to be ordered, even though they appear to be in the tabular form. Ordering of attributes in a relation schema R (and of values within each tuple):  We will consider the attributes in R(A 1, A 2,..., A n ) and the values in t= not to be ordered. Values in a tuple: All values are considered atomic (indivisible). A special null value is used to represent values that are unknown or inapplicable to certain tuples.

22 Chapter 5-22 Key Example: The STUDENT relation schema: STUDENT(stu_num, stu_name, gender, major, Year) has two keys Key1 = {stu_num}, Key2 = {stu_name} candidate keys:just keys If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The primary key attributes are underlined.

23 Relational Integrity Constraints Constraints are conditions that must hold on all valid relation states. There are three main types of constraints in the relational model:  Entity integrity constraints  Referential integrity constraints  User-define Constraints  Users define the constrains themselves Another implicit constraint is the domain constraint  Every value in a tuple must be from the domain of its attribute (or it could be null, if allowed for that attribute)

24 Chapter 5-24 Entity Integrity Entity Integrity: The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(R)and have different values. This is because primary key values are used to identify the individual tuples.

25 Entity integrity i.e : student ( stu_num , name , gender , age,major_num ) course ( course_num , curse_name , teacher ) select_course ( stu_num , course_num , grades )

26 Chapter 5-26 Referential Integrity A constraint involving two relations (the previous constraints involve a single relation). Used to specify a relationship among tuples in two relations: the referencing relation and the referenced relation. Tuples in the referencing relation R 1 have attributes FK (called foreign key attributes) that reference the primary key attributes PK of the referenced relation R 2. A tuple t 1 in R 1 is said to reference a tuple t 2 in R 2 if t 1 [FK] = t 2 [PK].

27 Chapter 5-27 Referential Integrity Constraint Statement of the constraint The value in the foreign key column (or columns) FK of the the referencing relation R 1 can be either: (1) a value of an existing primary key value of the corresponding primary key PK in the referenced relation R 2,, or.. (2) a null. In case (2), the FK in R 1 should not be a part of its own primary key.

28 i.e 1: student ( stu_num , name , gender , age,major_num ) major ( major_num , major_name ) Fore ign key Referen cing relation Referenc ed relation student major Major_num

29 Chapter 5-29 Other Types of Constraints Constraints: - based on application semantics and cannot be expressed by the model. - E.g., “the max. no. of hours per employee for all projects he or she works on is 56 hrs per week” - A constraint specification language may have to be used to express these - SQL-99 allows triggers and ASSERTIONS to allow for some of these

30 Chapter 5-30

31 Chapter 5-31 5.6

32 Chapter 5-32 5.7


Download ppt "Chapter 4 Rational data model. Chapter 5 Rational data model Chapter 4 Rational data model."

Similar presentations


Ads by Google