39
Modeller och språk för objekt-, relations- och webbdatabaser HT 2002

Modeller och språk för objekt-, relations- och webbdatabaser

Embed Size (px)

DESCRIPTION

Modeller och språk för objekt-, relations- och webbdatabaser. HT 2002. Data models. Relational, object, and semistructured. Types of database applications. Queries No queries. Payroll. GIS. Word processing. CAD/CAM. Simple data Complex data. An example schema. COMPANY. - PowerPoint PPT Presentation

Citation preview

Page 1: Modeller och språk för objekt-, relations- och webbdatabaser

Modeller och språk för objekt-, relations- och webbdatabaser

HT 2002

Page 2: Modeller och språk för objekt-, relations- och webbdatabaser

Data models

Relational, object, and semistructured

Page 3: Modeller och språk för objekt-, relations- och webbdatabaser

Types of database applications

Queries

Noqueries

Simple data Complex data

Wordprocessing

Payroll GIS

CAD/CAM

Page 4: Modeller och språk för objekt-, relations- och webbdatabaser

An example schema

EMPLOYEE

PERSON

ADDRESS

COMPANY

DEPARTMENT

departments

EMPLOYEEs

head_office

ISA

address

boss

ceo

office

Page 5: Modeller och språk för objekt-, relations- och webbdatabaser

An example schema

PERSON

namess#

DEPARTMENT

name

ADDRESS

streetcity

1

0..*

1

0..*

address

1

0..1

1

0..1

office

COMPANY

name

1..*

1

1..*

1

departments1

0..1

1

0..1head_office

EMPLOYEE

salary1..* 1..*1..* 1..*employees

1 0..11 0..1boss

1

0..*

ceo

0..*

1

Page 6: Modeller och språk för objekt-, relations- och webbdatabaser

A relational schema

COMPANY(CID, Name, Street, City, CEO) DEPARTMENT(CID, DeptName, Street, City,

Boss) PERSON(SS#, Name, Street, City) EMPLOYEE(SS#, Salary) EMPLOYMENT(CID, DeptName, Emp)

COMPANY.CEO << EMPLOYEE.SS#DEPARTMENT. CID << COMPANY.CIDEMPLOYEE.SS# << PERSON.SS#EMPLOYMENT.(CID, DeptName) << DEPARTMENT.(CID, DeptName)EMPLOYMENT.Emp << EMPLOYEE.SS#

Page 7: Modeller och språk för objekt-, relations- och webbdatabaser

Problems with the schema

Composite attributes do not exist Head office cannot be described directly but is decomposed into Street, City

Set valued attributes do not existThe fact that people are employed at departments is described in an extra table

Page 8: Modeller och språk för objekt-, relations- och webbdatabaser

Problems with the schema

Generalisation does not exist The generalisation relationship between EMPLOYEE and PERSON is not explicit

Artificial identifiers requiredCID is an artificial identifier for COMPANY

Page 9: Modeller och språk för objekt-, relations- och webbdatabaser

A SQL query

Which employees live at the same address, work at departments in London and earn more than 20000?

SELECT A.SS#, B.SS#FROM EMPLOYEE AS A, EMPLOYEE AS B,

EMPLOYMENT AS EMPL1, EMPLOYMENT AS EMPL2,PERSON AS P1, PERSON AS P2DEPARTMENT AS D1, DEPARTMENT AS D2

WHERE A.SS# = P1.SS#AND B.SS# = P2.SS#AND P1.Street = P2.StreetAND P1.City = P2.CityAND A.Salary > 20000 AND B.Salary > 20000AND EMPL1.SS# = A.SS#AND EMPL2.SS# = B.SS#AND EMPL1.CID = D1.CIDAND EMPL2.CID = D2.CIDAND EMPL1.DeptName = D1.DeptNameAND EMPL2.DeptName = D2.DeptNameAND D1.City = London AND D2.City = London

Page 10: Modeller och språk för objekt-, relations- och webbdatabaser

An object database schema

ADDRESS Street: String City: String

PERSON SS#: StringName: StringAddress: Address

EMPLOYEE ISA PERSON

Salary: IntegerBoss: EmployeeDepartments: {Department}

COMPANY Name: String Head office: Address Departments: {Department} CEO: Employee

DEPARTMENT Name: String Office: Address Boss: Employee Employees: {Employee}

Page 11: Modeller och språk för objekt-, relations- och webbdatabaser

An OO query

SELECT e1.ss#, e2.ss#FROM e1, e2 in EMPLOYEE; d1, d2 in DEPARTMENTWHERE e1 in d1.EmployeesAND e2 in d2.EmployeesAND e1.Address = e2.AddressAND e1.Salary > 20000 AND e2.Salary > 20000AND f1.Office.City = London AND f2.Office.City =

London

Are there employees who live at the same address, work at departments in London and earn more than 20000?

Page 12: Modeller och språk för objekt-, relations- och webbdatabaser

OODB models

Complex types

Types and classes

Object identity

Inheritance

Page 13: Modeller och språk för objekt-, relations- och webbdatabaser

Complex types

Base typesStringIntegerBoolean

ConstructorsTupleSetBagListArray

Page 14: Modeller och språk för objekt-, relations- och webbdatabaser

Complex types - an example

COORDINATEX: IntegerY: IntegerZ: Integer

PARKING SPOTPosition: COORDINATEOccupied: Boolean

CAR PARKSpots: ARRAY OF PARKING SPOTPersonnel: SET OF EMPLOYEE

The type constructors can be applied to any type - cf. the relational model

Page 15: Modeller och språk för objekt-, relations- och webbdatabaser

Relation schemes and relations

SS# Name Age Salary

650101-2288 Eva Svensson 33 25000750203-3133 Per Jonsson 23 20000500107-5532 Sven Olsson 47 25000800515-0044 Pia Eriksson 17 18000

PERSON

Relationscheme

Relation

Page 16: Modeller och språk för objekt-, relations- och webbdatabaser

Types and classes

A type is a time independent description of a set of (base or complex) values

A class has a time dependent extension that is a set of object identifiers

Page 17: Modeller och språk för objekt-, relations- och webbdatabaser

Object identity

Every object is identified by an object identifier

The object identifier does not change during the life span of the object

Two different objects with different object identifiers may have the same values

OID: 1088732Name: SimbaAge: 11Weight: 260

OID: 1293301Name: SimbaAge: 11Weight: 260

Page 18: Modeller och språk för objekt-, relations- och webbdatabaser

Object identity

The relational modelLion(Name, Age, Weight)

(Simba, 11, 260)

OO-modelLION Name: String Age: Integer Weight: Integer

1088732

OID: 1088732Name: SimbaAge: 11Weight: 260

Page 19: Modeller och språk för objekt-, relations- och webbdatabaser

Object identity

Why object identifiers are better than keys:

• Key attributes not stable

• Key values not stable

• Object sharing

Object identifiers can be used in relational databases but must be maintained by the users

Page 20: Modeller och språk för objekt-, relations- och webbdatabaser

Inheritance

The relational model

PERSON(SS#, Name, City)EMPLOYEE(SS#, Salary)

EMPLOYEE.SS# << PERSON.SS#

OO model

PERSON SS#: String Name: String City: String

EMPLOYEE ISA PERSON Salary: Integer

Employees are persons

Page 21: Modeller och språk för objekt-, relations- och webbdatabaser

Inheritance in the relational model

PERSON(SS#, Name, City)EMPLOYEE(Emp#, SS#, Salary)

EMPLOYEE.SS# << PERSON.SS#

PERSON

EMPLOYEE

ISA

PERSON(SS#, Name, City)EMPLOYEE(SS#, Spouse#, Salary)

EMPLOYEE.Spouse# << PERSON.SS#

PERSON

EMPLOYEE

spouse

Page 22: Modeller och språk för objekt-, relations- och webbdatabaser

Inheritance in OO databases

PERSONSS#: StringName: String

City: String

EMPLOYEE ISA PERSONEmp#: String

Salary: Integer

PERSONSS#: StringName: String

City: String

EMPLOYEEEmp#: String

Salary: Integer Spouse: PERSON

PERSON

EMPLOYEE

ISA

PERSON

EMPLOYEE

spouse

Page 23: Modeller och språk för objekt-, relations- och webbdatabaser

Extended base types

create table slides ( id int, date date, caption document, picture photo_CD_image);

create table landmarks ( name varchar(30), location point);

Find sunsets within a 20 kilometers radius around Sacramento.

select idfrom slides P, landmarks L Swhere sunset (P.picture) andcontains (P.caption, L.name) andL.location |20| S.location andS.name = 'Sacramento';

Page 24: Modeller och språk för objekt-, relations- och webbdatabaser

Types of DBMSs

Queries

Noqueries

Simple data Complex data

File systems

Relational OO/OR

OO

Page 25: Modeller och språk för objekt-, relations- och webbdatabaser

Why do we like types?

Types facilitate understanding

Types enable compact representations

Types enable query optimisation

Types facilitate consistency enforcement

Page 26: Modeller och språk för objekt-, relations- och webbdatabaser

Background assumptions fortyped data

Data stable over timeOrganisational body to control data

Exercise: Give an example of a context where these assumptions do not hold

Page 27: Modeller och språk för objekt-, relations- och webbdatabaser

Semistructured data

Semistructured data is schemaless and self describing

The data and the description of the data are integrated

Page 28: Modeller och språk för objekt-, relations- och webbdatabaser

Label-value pairs

{name: “John”, tel: 112233, email: “[email protected]”}

Label Value

“John” 112233 “[email protected]

name tel email

Page 29: Modeller och språk för objekt-, relations- och webbdatabaser

Nested label-value pairs

{name: {first: “John”, last: “Smith”}, tel: 112233, email: “[email protected]”}

“John” “Smith”

112233 “[email protected]

name tel email

first last

Page 30: Modeller och språk för objekt-, relations- och webbdatabaser

Duplicate labels

{name: {first: “John”, last: “Smith”}, tel: 112233, tel: 445566, tel: 778899, email: “[email protected]”}

Page 31: Modeller och språk för objekt-, relations- och webbdatabaser

Representing variations

{person:{name: “John”, tel: 112233, email: “[email protected]”},person:{name: “John”, email: “[email protected]”},person:{name: “John”, age: 33, email: “[email protected]”},person:{name: “John”, tel: 112233, tel: 332211}}

Page 32: Modeller och språk för objekt-, relations- och webbdatabaser

Representing relational data

Regno Manuf Weight

AA11 Volvo 1100CC33 Volvo 900EE55 Saab 1000

Ssno City Weight

1122 London 802233 Paris 703344 Berlin 80

CAR PERSON

{CAR:{row: {Regno: “AA11”, Manuf: “Volvo”, Weight: 1100},{row: {Regno: “CC33”, Manuf: “Volvo”, Weight: 900},{row: {Regno: “EE55”, Manuf: “Saab”, Weight: 1000}},PERSON:{row: {Ssno: “1122”, City: “London”, Weight: 80},{row: {Ssno: “2233”, City: “Paris”, Weight: 70},{row: {Ssno: “3344”, City: “Berlin”, Weight: 80}}}

Page 33: Modeller och språk för objekt-, relations- och webbdatabaser

An object graph

person person

name age name age

child

&o1 &o2

“Eva” 40 “Abel” 20

This graph represents two people, Eva and Abel, where Abel is the child of Eva.

&o1 and &o2 are object identifiers denoting the people Eva and Abel.

Page 34: Modeller och språk för objekt-, relations- och webbdatabaser

Representing objects

person person

name age name age

child

&o1 &o2

“Eva” 40 “Abel” 20

{person:&o1{name: “Eva”, age: 40, child: &o2},person:&o2{name: “Abel”, age: 20}}

An object identifier, such as &o1, before a structure, binds the object identifier to the identity of that structure. The object identifier can then be used to refer to the structure.

Page 35: Modeller och språk för objekt-, relations- och webbdatabaser

Finding Info on the Web

Suppose you spot the following news article in a paper and want to find contact information to the relevant scientists. What do you do?

A group of scientists from New Zealand have discovered a gene, called ADB, which increases the risk of catching the flu. The discovery was made possible thanks to the detailed registration in New Zealand of flu patients.

Page 36: Modeller och språk för objekt-, relations- och webbdatabaser

Searching and Navigating

This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is This may cause flu. about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is A gene called ADB about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is A gene called ADB about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases. This paper is about gentic causes to contagious diseases.

Genetic Causes to DiseasePeter Black, Eric, GreenNew Zealand Universitywww.nzu.nz/¨pg

Contact info

flu

ADB

gene

Page 37: Modeller och språk för objekt-, relations- och webbdatabaser

The Semantic Web

Structuring data in documents XML (eXtensible Markup Language)

Structuring data about documents RDF (Resource Description Framework)

Structuring the semantics of domains Ontologies - shared conceptualisations

Page 38: Modeller och språk för objekt-, relations- och webbdatabaser

Course goals

The course will familiarise the student with:

database models and query languages with respect to expressiveness and usability

theory and principles of object data bases semistructured data and its applications application areas for object and relational

databases interactive and embedded query languages Semantic Web, including ontologies

Page 39: Modeller och språk för objekt-, relations- och webbdatabaser

Lectures

1. Introduction to data models2. Query languages for relational databases3. Models and query languages for object

databases4. Embedded query languages 5. Models and query languages for

semistructured data, XML6. Semantic Web, introduction7. Semantic Web, continued