28
1 Desing Desing Data Data base base Systems Systems

1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

Embed Size (px)

Citation preview

Page 1: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

1

Desing Desing DataDatabase Systemsbase Systems

Page 2: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

2

Hierarchy databaseHierarchy database

•The structure of data is like a tree

•Parent-children relationship

•Pointers

Central depot

West depot East depot

Győr Pécs Szeged Debrecen

Page 3: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

3

Net database

Dairy collection

Centre

Area of Fót Area of Tata

Kiss János

Nagy Béla

Tóth Elek

The data are connected to each other like a ring, and these rings are the net model. (graph)

Page 4: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

4

Relations databaseRelations database YYou use ou use databasesdatabases

to organize and to organize and relate relate tablestables

Databases provide Databases provide the architecture the architecture for storing your for storing your data and have data and have additional benefits additional benefits as well.as well.

More details in More details in the next lecturethe next lecture

Page 5: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

5

Goals of the database design Goals of the database design process:process:

understand your data and why you’re tracking itunderstand your data and why you’re tracking it • • eliminate duplication of dataeliminate duplication of data • • eliminate redundant dataeliminate redundant data • • eliminate meaningless data or data we don’t care abouteliminate meaningless data or data we don’t care about • • promote accuracy of datapromote accuracy of data • • promote consistency of datapromote consistency of data • • make sure we can retrieve the information we need from make sure we can retrieve the information we need from

the databasethe database • • support the business functions that use the databasesupport the business functions that use the database • • build a database that lends itself to future growthbuild a database that lends itself to future growth

Page 6: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

6

Entity Relationship DiagramsEntity Relationship Diagrams(ERD)(ERD)

What is an ERD?What is an ERD?

An entity-relationship diagram is a An entity-relationship diagram is a data modeling technique that creates a technique that creates a graphical representation of the entities, and graphical representation of the entities, and the relationships between entities, within an the relationships between entities, within an information system. information system.

Page 7: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

7

Base Feaures of the ERDBase Feaures of the ERD

Simple, visual, graphical deviceSimple, visual, graphical device The models most important parts are the The models most important parts are the

entitiesentities and the relationships and the relationships It is built from the attributes of the entitiesIt is built from the attributes of the entities

Page 8: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

8

EntityEntity

An entity is an object or concept An entity is an object or concept about which you want to store about which you want to store

informationinformation..

Page 9: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

9

The common description of the entity is a rectangle, which contains the name of the entity:

Owner Dog

Description of the Entities

Page 10: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

10

Type of the EntitiesType of the Entities

EntityAn entity is an object or concept about which you want to store information

Weak EntityA weak entity is dependent on another entity to exist.

Page 11: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

11

AttributesAttributes

Attributes are the properties or Attributes are the properties or characteristics of an entity.characteristics of an entity.

Page 12: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

12

We can describe the attributes of the entity with a connecting ellipse:

Person

NameDate of birth

Place of birth

Sex

Description of the Attributes

Page 13: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

13

Types of the Attributes

AttributesAttributesAttributes are the properties or Attributes are the properties or characteristics of an entity. characteristics of an entity.

Key attributeKey attributeA key attribute is the unique, A key attribute is the unique, distinguishing characteristic of the distinguishing characteristic of the entity. For example, an employee's entity. For example, an employee's social security number might be the social security number might be the employee's key attribute. employee's key attribute.

Page 14: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

14

Types of the Attributes A multivalued attribute A multivalued attribute

can have more than one can have more than one value. For example, an value. For example, an employee entity can have employee entity can have multiple skill values. multiple skill values.

Derived attributeDerived attributeA derived attribute is A derived attribute is based on another attribute. based on another attribute. For example, an For example, an employee's monthly salary employee's monthly salary is based on the employee's is based on the employee's annual salary. annual salary.

Page 15: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

15

Page 16: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

16

RelationshipsRelationships

Relationships illustrate how two Relationships illustrate how two entities share information in the entities share information in the database structure.database structure.

Page 17: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

17

We can describe the relationship of the entity with a rhombus. We can mark the type of the relationship as well.

ManDoghas1 N

If an entity takes part in a connection only partly, we describe it with single line, (Not all men have dogs), if it takes part totally we describe it with a bold line.( We don’t respect the stray dogs)

Description of the Relationships

Page 18: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

18

Types of the Relationship RelationshipsRelationships

Relationships illustrate Relationships illustrate how two entities share how two entities share information in the information in the database structure.database structure.

Weak relationshipWeak relationshipTo connect a weak To connect a weak entity with others, you entity with others, you should use a weak should use a weak relationship notation. relationship notation.

Page 19: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

19

Cardinality

Cardinality specifies how many instances of an entity relate to one instance of another entity.

Page 20: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

20

CardinalityCardinality

»1:11:1 (wife-husband)(wife-husband)

»1: N1: N (mother-children)(mother-children)

»N:MN:M (grandparents-grandchildren)(grandparents-grandchildren)

Page 21: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

21

Examples - Relationship

1 Department may employ Many Employees1 Employee only has one department

Department EmployeesEmploys

1 N

The diagram changes according to your real situation.

Department EmployeesEmploys

M N

You may also allow 1 Employee to work for Many Departments

Page 22: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

22

ParticipationParticipation

»Total participationTotal participationEvery child has a motherEvery child has a mother

»Partial participationPartial participationNot every woman has a childNot every woman has a child

Page 23: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

23

Example - Participation

Every department must have at least one employee.An employee need not work for any department.Indicate partial participation by using

Department EmployeesEmploys

1 N

Page 24: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

24

Recursive Recursive relationshiprelationshipIn some cases, entities In some cases, entities can be self-linked. For can be self-linked. For example, employees example, employees can supervise other can supervise other employees. employees.

Page 25: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

25

Students Courses

ID LName FNameAddress

CNum CName Description

Relationship

Take

Entity

Entity

Attributes

Attributes

Page 26: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

26

Simplified car selling model

Car

Type

Years

Price

buy1

Customer

Address

Name

Driving licence

N

Page 27: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

27

DataData

Name Address Dlicense Type Year PriceKiss J. 1012 Ló 1 xy-1231 Trabant 500 36 5000Jó Ede 1042 Tó 1 wq-2345 Lada 1200 20 50000Kiss J. 1012 Ló 1 xy-1231 Fiat 600 18 40000Nagy G 1033 Kő 2 ww-1122 Kia 606 10 120000

Problems: - don’t give back the relationships- repeating data…

We have to study….

Page 28: 1 Desing Database Systems. 2 Hierarchy database The structure of data is like a tree Parent-children relationship Pointers Central depot West depotEast

28

buy1

Car

Type

Years

N

Price

sell1

Extension of the modelExtension of the model

Customer

Name

Address

Selling

Customer

Car

N

DateDriving licence