23
Analysis of Midterm-Examination Sept. 2012 ACS-3902 Yangjun Chen 1 1.(5) Describe the working process with a database system. a) database definition By the database definition, we create an entity- relationship diagram for a realistic world problem, which is then transformed into a database schema. b) populating tables with data The second phase is the database construction, by which a database is initially populated with data. c) database manipulation Once a database is constructed, one can conduct some operation on it, such as data insertion, data deletion and data updating, which changes the database from a state to

1.(5) Describe the working process with a database system. a) database definition

  • Upload
    koren

  • View
    41

  • Download
    0

Embed Size (px)

DESCRIPTION

1.(5) Describe the working process with a database system. a) database definition By the database definition, we create an entity-relationship diagram for a realistic world problem, which is then transformed into a database schema. b) populating tables with data - PowerPoint PPT Presentation

Citation preview

Page 1: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 1

1.(5) Describe the working process with a database system.

a) database definitionBy the database definition, we create an entity-relationship diagram for a realistic world problem, which is then transformed into a database

schema.

b) populating tables with dataThe second phase is the database construction, by which a database is initially populated with data.

c) database manipulationOnce a database is constructed, one can conduct some operation on it,

such as data insertion, data deletion and data updating, which changes the database from a state to another state. It is the responsibility of a database system to guarantee that the database goes from one correct state to

another.

Page 2: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 2

2.(10) Describe the three-schema architecture of a database system and the main functionality of each level in this architecture.

a) internal levelThe first level is the internal level, which possesses an internal

schema. It describes the physical storage structure of the database. The internal schema uses a physical data model and describes the complete details of data storage and access paths for the database.

b) conceptual levelThe second level is the conceptual level, which has a conceptual

schema. It describes the structure of the whole database for a community of users. The conceptual level hides the details of physical structures and concentrates on entity types, data types, relationships, user operations, and constraints. A high level data model or an implementation data model can be used at this level.

Page 3: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 3

c) external levelThe third level is the so-called external level or the view level, which includes a number of external schemas or user views. It describes the part of the database that aparticular user group is interested in and hides the rest of the database from that usergroup. A high level data model or the implementation data model can be used at thislevel.

Page 4: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 4

3.(10) Explain the following concepts:(a) superkey(b) key(c) candidate key(d) primary key(e) foreign key

key constraints•a superkey is any combination of attributes that uniquely

identify a tuple: t1[superkey] t2[superkey].•a key is superkey that has a minimal set of attributes

Page 5: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 5

•If a relation schema has more than one key, each of them is called a candidate key.

•one candidate key is chosen as the primary key (PK)•foreign key (FK) is defined as follows:

i) Consider two relation schemas R1 and R2;ii) The attributes in FK in R1 have the same domain(s) as the primary key

attributes PK in R2; the attributes FK are said to reference or refer to the relation R2;

iii) A value of FK in a tuple t1 of the current state r(R1) either occurs as a value of PK for some tuple t2 in the current state

r(R2) or is null. In the former case, we have t1[FK] = t2[PK], and we say that the tuple t1 references or refers to the tuple t2.

Page 6: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 6

4.(15) Draw an ER-diagram to describe the following real world problem.(a) A university is organized into faculties.

(b) Each faculty has a unique name, ID and number of professors and a specific professor is chosen as the faculty head.

(c) Each faculty provides a number of courses.(d) Each course has a unique name and courseID.(e) Each professor has a name, SIN, address, salary, sex and courses taught

by him/her.(f) Each professor belongs to a faculty and can teach several sections of a

course.(g) Each student has a name, ID, SIN, address, GPA, sex, and major.(h) Each student can choose one faculty as his/her major faculty and take

several courses with certain credit hours. Some of the courses are mandatory and some are optional.

Page 7: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 7

faculty

professor

student

ER-model:

belong

head

providechoose

teach

F-name F-Id NoProf

birthdatename sex major

name

sectionId

name ID addr.

startdate

1

1

1

N

NM

N

1M

N

take

SIN

sex

salary

MN

mandatory-optional

ID

SINaddr.

creditHours

couresId

sections

has

course1

M

Page 8: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 8

5.(30) Linear Hashing- collision resolution strategy: chaining- split rule: load factor > 0.7- initially M = 4 (M: size of the primary area)- hash functions: hi(key) = key mod 2i M (i = 0, 1, 2, …)- bucket capacity = 2

Trace the insertion process of the following keys into a linearhashing file:

24, 7, 10, 5, 14, 4, 1, 8, 2, 3, 17, 13, 15.

Page 9: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 9

The first phase – phase0

•when inserting the sixth record we would have

•but the load factor 6/8= 0.75 > 0.70 and so bucket 0 must be split (using h1 = Key mod 2M):

244 5 10

14

0 1 2 3

7

0 1 2 3 4

24 5 1014 7 4

n=0 before the split(n is the point to the bucket to be split.)

n=1 after the splitload factor: 6/10=0.6no split

Page 10: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 10

24 5 1014 7 4

0 1 2 3 4

n=1load factor: 7/10=0.7no split

insert(1)

24 51

1014 7 4

0 1 2 3 4

Page 11: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 11

24 51

1014 7 4

0 1 2 3 4

n=1load factor: 8/10=0.8split using h1.

insert(8)

248

51

1014 7 4

Page 12: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 12

0 1 2 3 4 5n=2load factor: 8/12=0.66no split

5248 1 10

14 7 4

0 1 2 3 4 5

5248 1 10

14 7 4

insert(2)

Page 13: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 13

n=2load factor: 9/12=0.75split using h1.

248 1 10

14 7 4

2overflow

5

0 1 2 3 4 5

248 1 10

2 7 4 5 14

Page 14: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 14

n=3load factor: 10/14=0.714split using h1.

248 1 10

2 7 4 5 14

248 1 10

273 4 5 14

insert(3)

Page 15: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 15

n=4

248 1 10

2 3 4 5 14 7

The second phase – phase1

824 1 10

2 3 4 5 14 7

n = 0; using h1 = Key mod 2M to insert and h2 = Key mod 4M to split.

insert(17)

Page 16: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 16

824

117

102 3 4 5 14 7

n=0load factor: 11/16=0.687no split.

824

117

102 3 4 5 14 7

insert(13)

Page 17: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 17

824

117

102 3 4 5

13 14 7

n=0load factor: 12/16=0.75split bucket 0, using h2.

117

102 3 4 5

13 14 7 824

Page 18: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 18

n=1load factor: 13/18=0.722split bucket 1, using h2.

117

102 3 4 5

13 14 7 824

insert(15)

117

102 3 4 5

13 14 715

824

117

102 3 4 5

13 14 715

824

Page 19: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 19

6.(15) Given the following B+-tree, trace the deletion sequence: h, c,e, f. Here, we assume that each internal node can contain at most twokeys and each leaf node can contain at most two value/point pairs.

hea b

c

b f

c f

Fig. 1

Page 20: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 20

fea

c

a e

b

fea b

c

b e

c

remove h:

remove c:

Page 21: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 21

b ba

a

a

c

a e

b

a

a e

f

f

remove e:

remove f:

Page 22: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 22

7.(15) Given the relation schemas shown in Fig. 2, construct expressions(using relational algebraic operations) to evaluate the following query:

Find the names of employees who works on all the projectscontrolled by department ‘Business Computing’.

fname, minit, lname, ssn, bdate, address, sex, salary, superssn, dno

Dname, dnumber, mgrssn, mgrstartdate

EMPLOYEE

DEPARTMENT

Pname, pnumber, plocation, dnum

PROJECT

Essn pno, hours

WORKS_ON

Fig. 2

Page 23: 1.(5) Describe the working process with a database system. a) database definition

Analysis of Midterm-Examination

Sept. 2012 ACS-3902 Yangjun Chen 23

DEPT_P PNUMBER(DNDN.dnumber = PROJECT.dnumber(PROJECT))

EMP_PNOS ESSN,PNO(WORK_ON)

SSNS EMP_PNOS : DEPT_P

RESULT FNAME, LNAME(SSNS * EMPLOYEE)

DN dnumber(Dname = ‘Business Computing’(Department))