Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity.

Similar presentations


Presentation on theme: "Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity."— Presentation transcript:

1 Relational data objects 1 Lecture 6

2 Relational data objects 2 Answer to last lectures activity

3 Relational data objects 3 Example used throughout the course Suppliers s_id (string); s_name (string); status (integer); city (string) Parts p_id (string); p_name (string); colour (string); weight (real); city (string) Contracted s_id (string); p_id (string); qty (integer)

4 Relational data objects 4 Diagrammatic representation

5 Relational data objects 5 Terminology Relation Attributes Degree Tuples Cardinality

6 Relational data objects 6 Domains

7 Relational data objects 7 Why domains? comparisons price with priceOK weight with weightOK weight with price !!! –POSSIBLE (they are both numbers) –BUT WRONG, i.e. MEANINGLESS integrity of the DB

8 Relational data objects 8 Why domains? - example SELECTP_name, Qty FROM Parts, Contracted WHERE Parts.P_id = Contracted.P_id SELECTP_name, Qty FROM Parts, Contracted WHERE Parts.P_id = Contracted.S_id Suppose the P_id and S_id fields are numeric in all tables meaningless

9 Relational data objects 9 Domains domains are not explicitly stored in the DB are specified as part of the DB definition (where?) each attribute - defined on a certain domain

10 Relational data objects 10 Scalars the smallest semantic unit of data atomic values - no internal structure with respect to the relational model NOTE: they may have internal structure comparison with a basic data type (Pascal) non-deterministic definition (slippery)

11 Relational data objects 11 Domain = data + operators integer: +, -, *, integer-division real char: concatenate, find string, … date: more complex data types spatial operators: all regions crossed by a line images

12 Relational data objects 12 Domains and data types domain (in the relational model) is the same with data type in a programming language analyse the extent to which domain / data type definition can be supported primitive support for domains in relational databases (INTEGER, CHAR(n),...)

13 Relational data objects 13 Data definition domains are not explicitly stored in the DB are specified as part of the DB definition (where?) each attribute - defined on a certain domain

14 Relational data objects 14 Conventions domains unique in the DB named relations unique in the DB attributes unique within a relation

15 Relational data objects 15 Domain based queries if domains exist which relations contain information related to… a certain domain (e.g. related to suppliers - S_id) if domains dont exist naming convention + attribute interrogation

16 Relational data objects 16 Domains - advantages domain constrained operators increased representational power spatial primitives for GIS; image processing features … domain based queries

17 Relational data objects 17 Relations

18 Relational data objects 18 Variable vs value variable - named object whose values can change value- element of a type DECLARE VARIABLE example OF TYPE INTEGER //... example := 1; // variable has certain value //... example := example * 2; // variable has certain value //...

19 Relational data objects 19 Relation variable vs relation value relation variable named object whose value at a given time is a relation value its values change with time relation value CREATE BASE RELATION example //... // insert operations SELECT //... FROM example// the variable has a certain value WHERE //...

20 Relational data objects 20 Relation value a relation value on a collection of domains (not necessarily distinct) consists of a heading and a body

21 Relational data objects 21 Relation heading a fixed set of attribute_name:domain_name pairs {,,..., } each A k corresponds to only one D k A 1,..., A n are all distinct degree (arity) - n

22 Relational data objects 22 Relation body a set of (n-)tuples n is the same for all the tuples in the set n-tuple a set of attribute_name:attribute_value pairs {,,..., } (tuple i) v ik must be from D k one and only one pair for each attribute cardinality - no of tuples

23 Relational data objects 23 Example - the relation Suppliers {,,, } heading { {,,, }, {,,, }, {,,, } } body

24 Relational data objects 24 Generate some incorrect examples

25 Relational data objects 25 Tables as relations relation table a table can be interpreted as a relation there are some underlying domains each column corresponds to a certain domain the tables heading represents the relations heading each row represents a tuple, etc.

26 Relational data objects 26 Properties of relations no duplicate tuples SQL!!! consequence - primary key tuples are un-ordered attributes are un-ordered all attributes are atomic 1NF; why do we need 1NF? unnormalised relation - example

27 Relational data objects 27 Kinds of relations named relation base relation derived relation expressible relation query result intermediate result view (virtual) snapshot (real) stored relation

28 Relational data objects 28 Relational database a database that is perceived by the user as a collection of normalised relations of assorted degrees (Codd, 1983)


Download ppt "Relational data objects 1 Lecture 6. Relational data objects 2 Answer to last lectures activity."

Similar presentations


Ads by Google