page 1kut introduction of db(1) what is db? 한국기술교육대학교 민준기

39
Page 1 KUT Introduction of DB(1) What is DB? 한한한한한한한한한 한한한

Upload: millicent-flynn

Post on 14-Dec-2015

232 views

Category:

Documents


2 download

TRANSCRIPT

Page 1KUT

Introduction of DB(1)What is DB?

한국기술교육대학교민준기

Page 2KUT

• Origin of “database” Term

– 1963.6 The first SDC Symposium• Development and Management of a Computer-centered

Data Base

– 1965.9 The second SDC Symposium• Computer-centered Data Base Systems

Definition of Database

Page 3KUT

History of Databases1960’s early The first Database, IDS(Integrated Data Store)

1960’s late Develop IMS(Information Management System) at IBM

May, 1970 Suggested Relational data model by Codd at IBM

1970’s early System/R, The first relational database

1979 Oracle V1, the first commercial relational DBMS

1982 SQL/DS, IBM’s commercial RDBMS

current Oracle, DB2, Sybase, SQL Server, etc

Page 4KUT

History of SQL

1973 SQUARE(Structured Queries As Relational Express)

1974System/R 용 SEQUEL(Structured English QUEry Language)

1976 SEQUEL-2

1980 Rename SQL(Structured Query Language)

1986 SQL-86, the first SQL standard spec

1988 ANSI, ISO international standard

1988 Publish SQL-1(SQL/89) standard

1992 Publish SQL-2(SQL/92) standard

1999 Publish SQL-3(SQL/99) standard

Page 5KUT

• Database – A collection of interrelated data

– For diverse application systems in a enterprise, a set of shared, integrated, stored and operational data

• shared data

• integrated data– minimal redundancy– controlled redundancy

• stored data– Stored media accessed by a computer

– Disk, tape, etc

• operational data

Definition of DB

Page 6KUT

• real-time accessibilities– real-time processing and response for a query

• continuous evolution– update, insert, delete : dynamic feature

• concurrent sharing– multi-users use simultaniously

• content reference– Not location or address of data– Reference by contents

Features of Database

Page 7KUT

• logical components– User view– Database = {entities, relationships}

• Entity– Object to be represented– Unit of information– Consist of attributes

• The smallest logical unit of data– entity set

• entity type vs. entity instance– Correspond to general record

• record type vs. record instance

Components of Database

Page 8KUT

8

Data world(1)

Real world(Entity)

Entity type

attribute

value

Conceptual world(concept) Computer World(Data)

Record type

field

value

feature

value

entity

facts abstraction

Conceptual modeling

Conceptual structure

Logical structure

(Data model)

Tansform

Data Modeling

Page 9KUT

9

data model• data model: D D = <S, O, C>

– S : structure)• Data’s static properties• Entity type and relationship

– O : operation• Data’s dynamic properties• Processing of entity instance

– C : constraints• logical constraints - existential condition of entity instance : derived from Structure S :semantic constraints• Limitation of data manipulation

Page 10KUT

개체 – 관계 모델 (E-R model)

• 현실세계의 개념적 표현

• 개체 타입과 관계 타입을 기본 개념으로 현실 세계를 개념적으로 표현하는 방법

• 개체 집합 : 한 개체 타입에 속하는 모든 개체 인스턴스

• 관계 집합 : 한 관계 타입에 속하는 모든 관계 인스턴스

Page 11KUT

11

Entity-Relationship model(E-R model)

• Entity-Relationship model

– conceptual data model

• Conceptual representation of real world

• ER model has three main concepts:– Entities (and their entity types and entity sets)– Attributes (simple, composite, multivalued)– Relationships (and their relationship types and

relationship sets)

Page 12KUT

12

entity type(1)• entity

– An object distinguished from others– Entities are specific objects or things in the mini-world that are

represented in the database

• entity type– Defined by name and attribute– entity set

• A set of entity instance

• Attribute Attributes are properties used to describe an entity.

i. Simple attribute, composite attributeii. Single value attribute , multi value attributeiii. Derived attribute, stored attributeiv. Null

Page 13KUT

13

relationship type• relationship type

– Correspondence between entity set(type), i.e., mapping

student enroll course

“enroll” relationship relationship typetype

Page 14KUT

14

▶ relationship type(1)

• mapping cardinality

– 1 : 1 (one to one: )

fx : x → y and fy : y → x marriage : bridegroom ↔ bride

– 1 : n (one to many)not fx : x → y but fy : y → x mothership : mother ← children

Page 15KUT

15

▶ relationship type(1)

– n : 1 (many to one) fx : x → y not fy : y → x

faculty : professor → department

– n : m (many to many) not fx : x → y not fy : y → x

enrollment : student ↔ course

☞ Note : functionality

Page 16KUT

16

▶ relationship type (2)

- participation constraint• total participation

– All entities in A participate in A-B relationship– ex) professor – department

• partial participation)– Some entities in A participate in A-B relationship– ex) marriage relationship

Page 17KUT

17

▶ E-R diagram(1)• 1976. Peter Chen

• E-R Diagram– entity type

– relationship type

– attribute

– link

– label : mapping • 1:1, 1:n, n:1, n:m

Page 18KUT

18

▶ E-R diagram(2)• example professor

student courseenroll

advice teachpno pname major dept

time

location

sno sname address year cno cname cpointgrade

n m

n

11

n

Page 19KUT

19

▶ key attributes

• An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. – For example, SSN of EMPLOYEE.

• A key attribute may be composite. – VehicleTagNumber is a key of the CAR entity

type with components (Number, State).• An entity type may have more than one key.

– The CAR entity type may have two keys:• VehicleIdentificationNumber (popularly called VIN)• VehicleTagNumber (Number, State), aka license plate

number.

• Each key is underlined

Page 20KUT

Slide 3- 20

Weak Entity Types• A weak entity must participate in an identifying relationship type

with an owner or identifying entity type

• weak entity type– An entity that does not have a key attribute– dominant entity – strong entity type, subordinate entity – weak entity type

• discriminator– Attribute identifying the particular weak entity who

are related to a strong entity type

• identifying relationship type

Page 21KUT

21

▶ E-R diagram

Entity type

Weak entity type

relationship

identifying relationship

type

total participation

attribute

Key attribute

Partial key attribute

Multi-valued attribute

Composite attribute

Derived attribute

Page 22KUT

22

▶ weak entity type

loan loan_repay

repaynum

n1

amountloanNum date repayamm

E-R diagram of “loan_repay” relationship

repay

Page 23KUT

Relational Database

• Relational Database

Page 24KUT

Slide 5- 24

Relational Model Concepts

• A Relation is a mathematical concept based on the ideas of sets

• The model was first proposed by Dr. E.F. Codd of IBM Research in 1970 in the following paper:– "A Relational Model for Large Shared Data Banks,"

Communications of the ACM, June 1970

• The above paper caused a major revolution in the field of database management and earned Dr. Codd the coveted ACM Turing Award

Page 25KUT

Slide 5- 25

Informal Definitions

• Informally, a relation looks like a table of values.

• A relation typically contains a set of rows.

• The data elements in each row represent certain facts that correspond to a real-world entity or relationship– In the formal model, rows are called tuples

• Each column has a column header that gives an indication of the meaning of the data items in that column– In the formal model, the column header is called an

attribute name (or just attribute)

Page 26KUT

26

Example of Relational Data model

학번(Sno)

이름(Sname)

학년(Year)

학과(Dept)

100 나 수 영 4 컴퓨터200 이 찬 수 3 전기300 정 기 태 1 컴퓨터400 송 병 길 4 컴퓨터500 박 종 화 2 산공

STUDENT Table : Relation

학생(STUDENT)

Page 27KUT

E-R Model vs. Relational Data Model• Entity Type Relation• Relation Type Relation• Attribute Attribute

• domain) – A set of values that an attribute can get

• attribute) – Action name of domain– Each name of attribute is unique

• simple domain→ atomic value

• composite domain→ composite value ex)yy, mm, dd date:<yy,mm,dd>⇒

Page 28KUT

Relation

• relation– 2 dimensional table structure– A set of tuples and attributes

STUDNO NAME USERID GRADE …… HEIGHT WEIGHT DEPTNO PROFNO

10101 전인하 jun123 4 …… 176 72 101 9903

20101 이동훈 Dals 1 …… 172 64 201

……… ……… ……… …… ………

10203 윤진욱 Samba 3 …… 171 70 102 9905

10107 이광훈 huriky 4 …… 175 92 101 9903

……… ……… ……… …… ………

Relation schema

instancestuple

attribute

Attribute nameSTUDENT relation

key

Page 29KUT

Slide 5- 29

Formal Definitions - Summary

• Formally,– Given R(A1, A2, .........., An)– r(R) dom (A1) X dom (A2) X ....X dom(An)

• R(A1, A2, …, An) is the schema of the relation n : R’s degree :1 차 , 2 차 , 3 차 , ... , n 차 ) num of tuples : cardinality

• R is the name of the relation• A1, A2, …, An are the attributes of the relation• r(R): a specific state (or "value" or “population”) of

relation R – this is a set of tuples (rows)– r(R) = {t1, t2, …, tm} where each ti is an n-tuple– ti = <v1, v2, …, vn> where each vj element-of dom(Aj)

Page 30KUT

Slide 5- 30

Formal Definitions - Example

• Let R(A1, A2) be a relation schema:– Let dom(A1) = {0,1}– Let dom(A2) = {a,b,c}

• Then: dom(A1) X dom(A2) is all possible combinations:{<0,a> , <0,b> , <0,c>, <1,a>, <1,b>, <1,c> }

• The relation state r(R) dom(A1) X dom(A2)

• For example: r(R) could be {<0,a> , <0,b> , <1,c> }– this is one possible state (or “population” or “extension”) r of

the relation R, defined over A1 and A2.– It has three 2-tuples: <0,a> , <0,b> , <1,c>

• Degree: 2• Cardinality: 3

Page 31KUT

1). uniqueness of tuplesRelation = Set of tuples

2). no ordering of tuplesRelation: Intension set of tuple

Table : Extension

3). no ordering of attributesRelation schema→ set of attributes

Tuple : set of <attribute: value> pairs

Characteristics of Relation(1)

Page 32KUT

32

Characteristics of Relation(2)

4). Atomicity of attribute

– atomic value

• indivisible

– normalized relation

• Relation with atomic attributes

• No-normalized relation=> decomposition=>Normalized relation

– null value is also atomic value

• unknown, inapplicable

Page 33KUT

• 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– 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)

• In order to explain Integrity constraints, we should know KEY.

Relational Integrity Constraints

Page 34KUT

• 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, SNO is the key

– Sometimes row-ids or sequential numbers are assigned as keys to identify the rows in a table

• Called artificial key or surrogate key

Key

Page 35KUT

• Superkey of R: – Is a set of attributes SK of R with the following

condition:• No two tuples in any valid relation state r(R) will have the

same value for SK• That is, for any distinct tuples t1 and t2 in r(R), t1[SK]

t2[SK]• This condition must hold in any valid state r(R)

• Candidate Key of R:– A "minimal" superkey– That is, a candidate key is a superkey K such that

removal of any attribute from K results in a set of attributes that is not a superkey (does not possess the superkey uniqueness property)

Key

Page 36KUT

• If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. – The primary key attributes are underlined.

• alternate key– Candidate keys except primary key

Key

Page 37KUT

Slide 5- 37

Key (continued)• Example: Consider the STUDENT relation schema:

– STUDENT(SNO, sNAME, SocialNo, Dept)– STUDENT has several super keys:

• Key1 = {SNO,sNAME, SocialNo, Dept}• Key2 = {SNO,sNAME}• Key3 = {SocialNo,sNAME}• Key4 ={SNO}

• {sNANE,Dept} is not a super key

– {SNO, sNAME} is a superkey but not a key.• In general:

– Any key is a superkey (but not vice versa)– Any set of attributes that includes a key is a superkey– A minimal superkey is also a key

• SNO and SocialNo are condidate keys– We choose SNO as a primary key– SocialNo is an alternative key

Page 38KUT

• foreign key– When Relation R’s attribute set FK is relation S’s

primary key, FK is called as R’s foreign key

– FK’s domain = Domain of S’s primary key

– FK’s value is in S or null

– R is referencing relation, S is referenced relation

Foreign Key

Page 39KUT

(1) entity integrity– Primary key value is not null.

☞ Notes : null value ① unknown value ② inapplicable

(2) referential integrity– The value in the foreign key column (or columns) FK of the the

referencing relation R1 can be either:• (1) a value of an existing primary key value of a corresponding

primary key PK in the referenced relation R2, or• (2) a null.

– In case (2), the FK in R1 should not be a part of its own primary key.

(3) Domain integrity– Every value in a tuple must be from the domain of its attribute

Integrity Constraints