CS352 - DATABASE SYSTEMS. To give you experience with developing a database to model a real domain

Similar documents
CS352 - DATABASE SYSTEMS

Chapter 6: Relational Database Design

Chapter 3: SQL. Chapter 3: SQL

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Silberschatz, Korth and Sudarshan See for conditions on re-use

Database System Concepts, 5 th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

CSCC43H: Introduction to Databases. Lecture 4

QQ Group

Chapter 3: SQL. Database System Concepts, 5th Ed. Silberschatz, Korth and Sudarshan See for conditions on re-use

Lecture 14 of 42. E-R Diagrams, UML Notes: PS3 Notes, E-R Design. Thursday, 15 Feb 2007

Simple SQL Queries (2)

Chapter 2: Relational Model

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database System Concepts, 5th Ed.! Silberschatz, Korth and Sudarshan See for conditions on re-use "

Database Systems CSE Comprehensive Exam Spring 2005

Chapter 7: Relational Database Design

Other Query Languages II. Winter Lecture 12

Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity Sets Extended E-R Features Design of the Bank Database Reduction to

DATABASE TECHNOLOGY. Spring An introduction to database systems

DATABASE DESIGN I - 1DL300

The SQL database language Parts of the SQL language

DATABASE MANAGEMENT SYSTEM

Example: specific person, company, event, plant

Information Systems and Software Systems Engineering (12CFU)

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

Views, assertions, and triggers

CSCC43H: Introduction to Databases. Lecture 3

Chapter 6: Entity-Relationship Model

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

BRANCH(branch_name: string, branch_city:string, assets:real) ACCOUNT(accno: int, branch_name:string, balance: real)

DATABASE DESIGN - 1DL400

Integrity and Security

UNIT 2 RELATIONAL MODEL

Chapter 5: Other Relational Languages

Other Relational Query Languages

Chapter 6: Entity-Relationship Model

Database Systems. Answers

The Relational Model

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

1. (a) Explain the Transaction management in a database. (b) Discuss the Query Processor of Database system structure. [8+8]

Chapter 1: Introduction

ADVANCED SQL DDL. CS121: Relational Databases Fall 2017 Lecture 10

CMSC 424 Database design Lecture 18 Query optimization. Mihai Pop

DATABASE DESIGN - 1DL400

The Next Step: Designing DB Schema. Chapter 6: Entity-Relationship Model. The E-R Model. Identifying Entities and their Attributes.

Chapter 6: Entity-Relationship Model

customer = (customer_id, _ customer_name, customer_street,

DBMS: AN INTERACTIVE TUTORIAL

Chapter 6: Entity-Relationship Model. The Next Step: Designing DB Schema. Identifying Entities and their Attributes. The E-R Model.

DATABASDESIGN FÖR INGENJÖRER - 1DL124

Database Management System. Fundamental Database Concepts

SQL QUERIES. CS121: Relational Databases Fall 2017 Lecture 5

Chapter 1: Introduction

CSE 132A Database Systems Principles

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

Contents Contents Introduction Basic Steps in Query Processing Introduction Transformation of Relational Expressions...

Database System Concepts

Database Management Systems (CPTR 312)

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

ENTITY-RELATIONSHIP MODEL III. CS121: Relational Databases Fall 2017 Lecture 16

Lecture 3 SQL. Shuigeng Zhou. September 23, 2008 School of Computer Science Fudan University

SQL. Lecture 4 SQL. Basic Structure. The select Clause. The select Clause (Cont.) The select Clause (Cont.) Basic Structure.

Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries Derived Relations Views Modification of the Database Data Definition

6.1 RELATIONSHIP CONCEPTS

Chapter 2: Relational Model

II. Review/Expansion of Definitions - Ask class for definitions

Chapter 4. The Relational Model

Chapter 8: Relational Algebra

Other Query Languages. Winter Lecture 11

D.Hemavathi & R.Venkatalakshmi, Assistant Professor, SRM University, Kattankulathur

CS122 Lecture 5 Winter Term,

Chapter 1: Introduction

Database Systems SQL SL03

Chapter 1 Chapter-1

Chapter 1: Introduction. Chapter 1: Introduction

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Outline. Note 1. CSIE30600 Database Systems More SQL 2

Database Systems SQL SL03

Chapter 4: Advanced SQL

Entity-Relationship Model

Chapter 14: Query Optimization

INF1383 -Bancos de Dados

Chapter 6: Formal Relational Query Languages

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

First lecture of this chapter is in slides (PPT file)

Relational Algebra. Relational Algebra. 7/4/2017 Md. Golam Moazzam, Dept. of CSE, JU

Chapter 6: Integrity and Security.! Domain Constraints! Referential Integrity! Assertions! Triggers! Security! Authorization! Authorization in SQL

A database can be modeled as: + a collection of entities, + a set of relationships among entities.

Lecture 11 - Chapter 8 Relational Database Design Part 1

Chapter 6: Entity-Relationship Model. E-R Diagrams

<account_number> A-101 </account_number># <branch_name> Downtown </branch_name># <balance> 500 </balance>#

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

1. Considering functional dependency, one in which removal from some attributes must affect dependency is called

Let s briefly review important EER inheritance concepts

Database System Concepts"

Data about data is database Select correct option: True False Partially True None of the Above

CS275 Intro to Databases

2. E-R Model. Entity Sets Relationship Sets Attributes

Transcription:

CS352 - DATABASE SYSTEMS Database Design Project - Various parts due as shown in the syllabus Purposes: To give you experience with developing a database to model a real domain Requirements At your option, this project may be done by a team of two students. This project is deliberately made quite open-ended. 1. Choose a domain with which you are familiar - other than one of the domains used for examples in the book (banking) or lecture (a library). See discussion on Choosing an Appropriate Domain below. If you wish, you may choose an appropriate subset of a larger domain. 2. Develop an E-R diagram for a database that models this domain (or the chosen subset). 3. Turn your E-R diagram into a normalized relational database design for the (subset of the) domain - i.e. a set of tables, each with appropriate attributes, a primary key, and appropriate foreign keys. The database should be a based on the E-R diagram, but one-to-one and one-tomany relationships may be implemented by appropriate attributes in the one entity, rather than as separate tables. Of course, your relational database must be 4NF! 4. Implement your database design a. Create a file of SQL create statements. b. Create your database under your username (or the username of one of the partners) as a schema in the design database (i.e. you won t actually create the database itself, just the tables, etc, within a schema in it.) c. Populate your database with sample data to allow testing of the schema and the various transactions. Each table should have a minimum of five rows d. Thoroughly test your constraints using your sample data (by ensuring that your constraints correctly catch various kinds of invalid insert/update/delete operations). Note that the comprehensiveness of your test data will be a factor in the grading of this part of the project! Turn in: Your project will be turned in in four parts. You may wish to modify your approach/design for subsequent parts based on professor feedback from each part. (You do not need to redo the prior part unless you totally change the project!) The value of each part in the final course grade will be as shown below (20% total for the whole project.) Part I - Requirements (3% of final course grade) 1. A description of the problem domain (written using terminology that a user of the system would use, not techical database terminology. 2. A statement of requirements. You may express this in requirements language, or you may find it useful to prepare a use case diagram and perhaps simplified use cases. (See example systems from CS211). 1

Part II - E-R Diagram (5% of final course grade) 1. An ER diagram for your database, including attributes for entities and relationships. Part III - Relational Database Design (5% of final course grade) 1. A list of the functional and multivalued dependencies for your scheme. 2. A schema diagram for your database, with primary and foreign keys specified appropriately. Part IV - Relational Database Implementation/Sample Data (7% of final course grade) 1. A printout of a file containing your SQL "create" statements that create the database. 2. The test data you used to thorougly test your constraints. You should include some comments indicating what specific problem you were testing for with bad data - but be sure to include good data as well! (Note: you do not need to test not null constraints.) 3. Printouts of the sample data contents of the various tables (the results of select * from...) and of the results of your tests indicating that your constraints correctly allowed good data and caught bad data. An Example: (Note: this example is much simpler than what you would actually do for the project - it s only meant to illustrate what the various pieces of the project need to include.) 1. Suppose you chose a subset of the domain of banking, as in the examples in the book. (As noted above, you can t actually choose this domain, of course!) Section 1.6.2 in the book describes this system; you would also need to spell out the requirements, perhaps by using a use case diagram like that shown on the next page. (Cases pertaining to managing the set of branches and to managing information about employees are excluded, as is any consideration of access via an ATM) 2. Your design might be based on an E-R diagram like figure 6.25 in the book. (Note: other examples in the book use the customer name as the primary key, rather than having a separate customer_id attribute. This is actually not a good idea, but we will follow the approach of the other book examples to avoid confusion! Therefore, pretend that the E-R diagram does not have a customer_id attribute. We'll also omit features of the E-R diagram pertaining to employees different types of accounts and loan payments from the rest of this example.) 3. The following FD's hold on the E-R diagram, modified/abbreviated as noted above. branch_name branch_city, assets customer_name customer_street, customer_city account_number branch_name, balance loan_number branch_name, amount customer_name >> account_number account_number >> customer_name customer_name >> loan_number loan_number >> customer_name 2

A database schema based on these dependencies might look like figure 2.8 in the book. (Note: this does not correspond exactly to the E-R diagram - the book authors have not tried to develop a single example consistently throughout the book!) No tables are needed corresponding to account_branch or loan_branch in the E-R diagram - attributes of these relationships can be folded into the account and loan tables because each relationship is 1:many. Add customer Branch officer Delete customer Open checking account Personal banker Open savings account Create loan Loan officer Update customer information Accept deposit Teller Perform withdrawal Accept loan payment 4. This database could be created by the following SQL statements. Named domains are created for each of the primary keys of the four entities, plus one for representing money amounts. DB2 automatically creates indexes for each primary key, so we don't need to do this here (but on some systems it might be necessary to explicitly do so.) We also index depositor and borrower by loan_number (but not by customer_name - assume we most often lookup depositor and borrower information on accounts and loans by number.) When an account is deleted, the specification of cascading delete in the references clause of depositor causes the relevant depositor row(s) to also be deleted. The same holds for loan and borrower. 3

A trigger is used so that when a loan is deleted (which cascades to delete the borrower row(s)), the borrower(s) is/are also deleted from the customer table if they have no other outstanding loans and are not depositors. (Something similar could also be done for accounts)> A view is created to allow clerical employees of the Perryridge branch to access full customer information on all the borrowers who have loans at the branch, but not details about the loan. For this problem, it is reasonable to constrain all attributes to be not null. (This would not necessarily always be the case - in some cases it is meaningful for a particular attribute to be null). create distinct type branch_name_t as char(10) with comparisons; create distinct type customer_name_t as char(30) with comparisons; create distinct type account_number_t as integer with comparisons; create distinct type loan_number_t as integer with comparisons; create distinct type money_t as decimal(12, 2) with comparisons; create table branch( branch_name branch_name_t not null primary key, branch_city char(30) not null, assets money_t not null); create table customer( customer_name customer_name_t not null primary key, customer_street char(30) not null, customer_city char(30) not null); create table account( account_number account_number_t not null primary key, branch_name branch_name_t not null references branch, balance money_t not null); create table loan( loan_number loan_number_t not null primary key, branch_name branch_name_t not null references branch, amount money_t not null); create table depositor( customer_name customer_name_t not null references customer, account_number account_number_t not null references account on delete cascade); create table borrower( customer_name customer_name_t not null references customer, loan_number loan_number_t not null references loan on delete cascade); -- db2 automatically creates the primary key indexes for three tables create unique index dep_acct_no_index on depositor(account_number); create unique index borr_loan_no_index on borrower(loan_number); create trigger del_if_not_cust after delete on borrower referencing old as delrow for each row mode db2sql when (delrow.customer_name not in (select customer_name from borrower) and delrow.customer_name not in (select customer_name from depositor)) delete from customer where customer.customer_name = delrow.customer_name; create view perryridge_borrowers as select customer.* from (loan join borrower on loan.loan_number = borrower.loan_number) join customer on customer.customer_name = borrower.customer_name where branch_name = cast('perryridge' as branch_name_t); 4

Of course, each of the constraints (except the not null ones) must be tested by appropriate data. For example, the following would test the primary key and foreign key constraints on account (assuming that the Perryridge branch was already created.) insert into account values(12345, 'Perryridge', 100.00); insert into account values(12345, 'Perryridge', 200.00); insert into account values(98765, 'No such', 100.00); (fails PK) (fails FK) Documentation for this test would consist of a screen shot showing DB2 giving an error message for each of the two invalid inserts. The trigger could be tested by the following: insert into customer values ('Aardvark', 'Jenks subbasement', 'Wenham'); insert into loan values (1234, 'Perryridge', 100.00); insert into borrower values ('Aardvark', 1234); delete from borrower where loan_number = cast (1234 as loan_number_t); the last statement should also result in the deletion of the customer row for 'Aardvark' - i.e. a select * from customer should show a row for Aardvark before the deletion is done, but not after. Documentation for this test would consist of a screen shot showing the result of the latter select statement. Choosing an Appropriate Domain The domain (or subset of a domain) that you choose for your project should have the following characteristics: 1. Size. An appropriate-size domain will result in a database having about a dozen tables (more or less). 2. The entities comprising your domain should be interrelated. 3. Your schema should include some attributes which make it possible to include some transactions that involve aggegate functions. (For example, the schema developed above would allow for a queries to calculate the total of all loans for each branch, or the average loan size of each branch, or the total of all loans for each customer, etc.) 5