10
Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客客 ( 客客客 , 客客客 ) 5. account 客客客 3. depositor 客客客 6. loan 客客客 4. borrower 客客客 客客客 國國國國國國國國 : 國國國國國 客客客客客客 2012.04.17

Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Embed Size (px)

Citation preview

Page 1: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1

Example:Banking Database

1. branch 2. customer客戶 ( 存款戶 , 貸款戶 )

5.

account

存款帳

3. depositor 存款戶

6. loan 貸款帳 4. borrower 貸款戶

分公司

國立東華大學試題 : 資料庫管理 資訊管理學系 2012.04.17

Page 2: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 1: Answer the following Terms (30%)

a) Goal of a DBMS.

b) Functions of a DBMS

c) Relational Database

d) Data Dictionary in DBMS

e) Schemas and Instances

f) Physical Data Independence

g) Query Processor

h) Storage Manager

i) Database administrator

j) Authorization and Integrity Manager

k) Query evaluation engine

l) Three levels of an architecture for a database system

m) Relational-Algebra Operation: Cartesian product

n) Relational-Algebra Operation: Natural Join

o) Aggregate Functions

2012 Midterm Test-2

Page 3: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 2: Data-Definition Language (10%)

Consider the following Table Definition:

a) What is the purpose to define: primary key (branch-name),

b) What is the purpose to define: check (assets >= 0)

c) 這些定義的指令存在那裡 ? 有何用途 ? 如何使用 ?

create table branch(branch-name char(15),branch-city char(30),assets integer,primary key (branch-name),check (assets >= 0))

2012 Midterm Test-3

Page 4: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 3: Flow of Query Processing (10%)

Explain the following three tasks:

a) Parsing and translation

b) Optimization

c) Evaluation

2012 Midterm Test-4

Page 5: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 4: Using the following Example to explain theReferential Integrity Constraint (10%)

create table account(account-number char(10),branch-name char(15),balance integer,

primary key (account-number),

create table depositor(customer-name char(20),account-number char(10),

primary key (customer-name, account-number), foreign key (account-number) references account,

3. account

4. depositorreferences

( 存款戶 )

( 存款帳 )

2012 Midterm Test-5

Page 6: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 5: Updates (10%)

Query: Increase all accounts with balances over $700 by 6%, all other accounts receive 5%.

Consider two update statements:

update accountset balance = balance 1.06where balance > 700

update accountset balance = balance 1.05where balance 700

a) Give the account table after execute the above two update statements.

b) The order is important, why?

c) Please write a SQL by using the case statement for above update statements.

2012 Midterm Test-6

Page 7: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

account

Question 6: Definition of Relation (10%)

Relation:

Formally, given sets D1, D2, …. Dn

D1 x D2 x … x Dn = {(a1, a2, …, an)

| where each ai Di}

a Relation r is a subset of D1 x D2

x … x Dn

Thus a relation is a set of n-tuples (a1, a2, …, an) where

each ai Di

D1 = { }

D2 = { }

D3 = { }

D1 x D2 x D3 =

account =

a) Write

b) Write

c) Why the Relation r is a subset of D1 x D2 x … x Dn , please

explain it by using above example.

2012 Midterm Test-7

Page 8: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Query: “Find the names of all customers who have a loan at the Perryridge branch.

Query 2

customer-name (loan.loan-number = borrower.loan-number ( (branch-name = “Perryridge” (loan)) x borrower))

Query 1

customer-name (branch-name = “Perryridge” ( borrower.loan-number = loan.loan-number (borrower x loan)))

Question 7: Comparison (10%)

c) Which one is better? Why?

a) ?

b) ?

2012 Midterm Test-8

Page 9: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 8: multiple relations vs. Single relation (10%)

Database: A database consists of multiple relations Information about an enterprise is broken up into parts, with each

relation storing one part of the information

E.g.: account: stores information about accounts depositor: stores information about which customer owns which account customer: stores information about customers

If we store all information as a single relation such as bank(account-number, balance, customer-name, ..)

Question: The table bank may contain a lot of repetition of information and null values, why?

bank

2012 Midterm Test-9

Page 10: Introduction to Database System Wei-Pang Yang, IM.NDHU, 2010 2012 Midterm Test-1 Example: Banking Database 1. branch 2. customer 客戶 ( 存款戶, 貸款戶 ) 5. account

Introduction to Database SystemWei-Pang Yang, IM.NDHU, 2010

Question 9: Database System vs. File System (10%)

In the early days, database applications were built on top of file systems

Drawbacks of using file systems to store data are:

a) Data redundancy and inconsistency, why?

b) Difficulty in accessing data, why?

c) Integrity problems, why?

d) Application program unstable, why?

e) Database systems offer solutions to all the above problems, why?

2012 Midterm Test-10