database design intro(database)

116
ISOM3260 Database Design and Administration Lab 1: Introduction to Labs and Team Project 1 Agenda of today 1. Introducing… Myself Lab sessions of the course Team project of the course <<< Short Break >>> 2. Project case and the requirements 3. Tips for doing the project 2 ISOM3260 Lab (Stage 1) 1

Upload: welcometofacebook

Post on 19-Jun-2015

1.398 views

Category:

Engineering


7 download

TRANSCRIPT

Page 1: database design intro(database)

ISOM3260 Database Design and Administration

Lab 1: Introduction to Labs and Team Project

1

Agenda of today

1. Introducing…

– Myself 

– Lab sessions of the course

– Team project of the course

<<< Short Break >>>

2.  Project case and the requirements

3. Tips for doing the project

2

ISOM3260 Lab (Stage 1) 1

Page 2: database design intro(database)

Lab Instructor

Name: Chris Tse

Office: LSK4065

Contact: [email protected], 2358‐7653

Office Hours: By Appointment

3

Lab Sessions Schedule

• 3 hours lab per week

LA1 (Thu 3:00pm ‐ 5:50pm)

LA2 (Tue 3:00pm ‐ 5:50pm)

LA3 (Thu 10:30am ‐ 1:20pm)

LA4 (Tue 10:30am ‐ 1:20pm)

4

ISOM3260 Lab (Stage 1) 2

Page 3: database design intro(database)

Agenda of Laboratory Sessions

• Hands‐on practice on the previous lab materials

• Demonstration of new materials

• Hands‐on Practice

• Project work

Makeup tutorial sessions may be arranged over the semester

5

Course Website

• http://teaching.ust.hk/~isom3260

• Requires ITSC account and password to login

• Lab materials and other supplementary materials will be put on the website

– Let me know if you cannot log in

6

ISOM3260 Lab (Stage 1) 3

Page 4: database design intro(database)

Objectives of Laboratory Sessions

• Analyze, design and develop an application to solve authentic business problems

• Learn to write 2 programming languages ‐PL/SQL and SQL

• Understand the use of different components of a System Development tool – Oracle Developer Suite

7

Topics in Lab Sessions

Lab Sessions

Analysis, Design

Toad Data Modeler

Implementation, Maintenance

Oracle Forms Developer

SQL ToolsOracle Reports Developer and integration

8

ISOM3260 Lab (Stage 1) 4

Page 5: database design intro(database)

Topics in Lab SessionsWeek Topics

Week 2 - 3 Toad Data Modeler –Design the data structure using ERD

Week 3 - 5 Oracle Forms Developer (Stage 1) –Develop simple interfaces of an information system using PL/SQL

Week 6 No Lab - Progress Demonstration 1 (7%)

Week 7- 9 Oracle Forms Developer (Stage 2) –Develop advanced interfaces of an information system using PL/SQL

Week 10 No Lab - Progress Demonstration 2 (8%)

Week 11 Oracle Reports Developer and integration –Develop managerial reports for an information system

Week 12 Project Consultation

Week 13 Project Demonstration9

Software in ISOM3260

• 2 Servers: Oracle Database 11g (Release 2)– Microsoft Windows Server Platform

• Client: – Toad Data Modeler Freeware

• Design database through entity‐relationship diagram

– Oracle Developer Suite 10g (10.1.2)• Forms Developer – build user interfaces for users to manipulate the data stored in 

a database 

• Reports Developer – generate managerial reports 

– SQL Tools• Allow developers (i.e., you) to access a database using SQL commands

• Client software are available at PC Lab 1 and 2 (LSKG005 and LSKG021)

10

ISOM3260 Lab (Stage 1) 5

Page 6: database design intro(database)

Two‐tier Architecture

Toad Data Modeler, Oracle Developer Suite and

SQL Tools are installed here!!

Oracle Databaseis installed here!!

There are databases under 2 servers – IMZ350.ust.hk and IMZ335.ust.hk 11

Team Project

• To develop an information system for selling off‐the‐shelf software packages

• 6 members per group ‐MUST be in the same LAB session

12

ISOM3260 Lab (Stage 1) 6

Page 7: database design intro(database)

Learning Outcomes of the Team Project

• Develop an authentic information system– Simulating the work of an actual IT project team in an IT consultancy firm (eg. Oracle, IBM, etc)

• Learn to apply programming skills in business contexts– IF statements, Loops, Functions and Procedures

• Learn to collaborate with others in a team• Realize your strength in different aspects in a typical IT project for future career planning– Analysis and design?– Programming? – Documentation?– Graphic design?– Take leading role?

13

Project Grading (I)

Deliverables Date Marks

Progress Demonstration 1  Mar 13, 14 7%

Progress Demonstration 2  Apr 10, 11, 15 8%

Final PresentationFinal Report

May 7, 8 ,9 15%

Total Score 30%

14

ISOM3260 Lab (Stage 1) 7

Page 8: database design intro(database)

Project Grading (II)

• Peer Evaluation

– Individual score of the team project will be adjusted, base on the contribution in the team

15

16

ISOM3260 Lab (Stage 1) 8

Page 9: database design intro(database)

Kick‐off the project

• Form a cohesive team

• Elect a “Project Leader”

• Send the group list to [email protected] Feb 18

• Your group list should contain

– Names and student IDs of group members

– Lab session number

– Email addresses

17

Tips

• Form the groups by this week/next week

• Keep up with the lab topics and work accordingly on your project and work together during the lab sessions

• Plan ahead for the Progress Demonstrations 1, 2

• Complete the project early and perform detailed testing 

18

ISOM3260 Lab (Stage 1) 9

Page 10: database design intro(database)

ISOM3260 Database Design and Administration

Lab 2: Toad Data Modeler

1

Topics in Lab Sessions

Oracle Project

Analysis, Design

Toad Data Modeler

Implementation, Maintenance

Oracle Forms Developer

SQL ToolsOracle Reports Developer and integration

2

ISOM3260 Lab (Stage 1) 10

Page 11: database design intro(database)

Agenda

Oracle Project

Analysis, Design

Toad Data Modeler

Implementation, Maintenance

3

Agenda

• Introduction to Entity‐relationship diagram

• Draw ERD using a CASE Tool – Toad Data Modeler

Entities

Relationship

Attributes, Datatype

• Create a physical database from an ERD

• Check the accuracy of the physical database

4

ISOM3260 Lab (Stage 1) 11

Page 12: database design intro(database)

Introduction to Entity‐relationship Diagram

5

Partial View of an Online Purchasing System

6

Search products and view detail

Register as a member

ISOM3260 Lab (Stage 1) 12

Page 13: database design intro(database)

Entity: Customer

7

Customer

Attributes/information the system stores for a customer

CUS_IDCUS_LNameCUS_FNameCUS_UIDCUS_PWDCUS_Email

Attributes

A customer record

8

ylx008

******

******

[email protected]

Peter

Johnson

CUS_ID CUS_LName CUS_FName CUS_UID CUS_PWD CUS_Email

C0001 Johnson Peter ylx008 ****** [email protected]

C0002 Alex Ng ang098 ****** [email protected]

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

A customer record in the customer table

ISOM3260 Lab (Stage 1) 13

Page 14: database design intro(database)

Entity: Product

9

Product

PRO_IDPRO_NamePRO_SKUPRO_Price

PRO_ID PRO_Name PRO_SKU PRO_Price

PD0001 Apple iPhone 5 00063 $199

PD0002 Apple iPad 2 00062 $499

…… …… …… ……

A product record/instance

Attributes

Relationship

10

• What does relationship mean in an ERD?

DOCTORAPPOINTMENT

PATIENT

ISOM3260 Lab (Stage 1) 14

Page 15: database design intro(database)

Toad Data Modeler is a CASE Tool

• CASE = Computer‐Aided Software Engineering

– Transform from logical design to physical tables

– Entity Relationship Diagram  Oracle DB 

– Other CASE tools in the market

• MS Visio, IBM Rational Rose, Oracle Designer, etc

11

Steps in creating a database using Toad Data Modeler

1. Draw ERD

2. Check the ER Model

3.Toad Data Modeler 

Conversion

4. Create real tables in 

the Database

5.Check the real tables

12

ISOM3260 Lab (Stage 1) 15

Page 16: database design intro(database)

Class Exercise

• Create a ER Model using Toad Data Modeler for Spirit Cruise Line

13

Caution 1: Entity naming

• Do NOT use Oracle reserved word for entity name

• Use BLOCK letters 

• A common Oracle reserved word that students use : ORDER

– Use ORDERS/ORDER_DATA instead

14

ISOM3260 Lab (Stage 1) 16

Page 17: database design intro(database)

Caution 2: Define attribute datatype

• VARCHAR2 (Size)

– Variable Length characters (recommended)

• NUMBER (Precision, Scale)

– Real Numbers, for calculation

• DATE

– Date (From January 1, 4712BC to December 31, 31999AD)

15

Steps in creating a database using Toad Data Modeler

1. Draw ERD

2. Check the ER Model

3.Toad Data Modeler 

Conversion

4. Create real tables in 

the Database

5.Check the real tables

16

ISOM3260 Lab (Stage 1) 17

Page 18: database design intro(database)

Class Exercise

1. Convert the ER Model into a set of code

– Refer Lab 2 lab manual

2. Execute the code into Database using    SQLTools

17

Verify the tables in the database (1)

• Use SQLTools 1.5 

• Login with Oracle personal account

18

ISOM3260 Lab (Stage 1) 18

Page 19: database design intro(database)

Verify the tables in the database (2)

Tables created through Toad Data Modeler

19

Verify the tables in the database (3)

• Type the following SQL statements :Check tables in your database

SELECT table_name

FROM user_tables; 

Check the metadata of your tables

SELECT column_name, data_type, data_length

FROM user_tab_columns

WHERE table_name=‘<table name>’;

Check the constraints of your tables

SELECT constraint_name, constraint_type,

search_condition

FROM user_constraints

WHERE table_name=‘<table name>’; 20

ISOM3260 Lab (Stage 1) 19

Page 20: database design intro(database)

Summary

21

What is an entity‐relationship diagram?

22

• Entities are converted into real tables for data storage

DOCTORAPPOINTMENT

PATIENT

ISOM3260 Lab (Stage 1) 20

Page 21: database design intro(database)

Steps of creating a database

1. Draw ERD

2. Check the ER Model

3.Toad Data Modeler 

Conversion

4. Create real tables in 

the Database

5.Check the real tables

23

Draw ERD and convert ERD into real tables using Toad Data Modeler

24

ISOM3260 Lab (Stage 1) 21

Page 22: database design intro(database)

Check the physical tables using SQL Tools

25

Start the team project this week1. Form your team2. Refer to the list of basic functions, come up the 

data required to build this information system3. Drafting an ERD on a piece of paper (or on 

Toad), base on the basic functions4. (Optional) Pick a set of extra functions that you 

want to implement5. (Optional) Modify the ERD base on the 

additional functions you suggest

Note:• EVERY group should report the current progress to me next 

week

26

ISOM3260 Lab (Stage 1) 22

Page 23: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 1 of 9 

Lab 2 : Creating a database using Toad Data Modeler 

 

 

1. Introduction 

Toad Data Modeler is an application for designing databases. ER diagrams can be created visually in 

Toad Data Modeler. The program then automatically generates Data Definition Language for 

creating a database. The freeware version of the program, Toad Data Modeler 2.25, can be 

downloaded in http://en.utilidades‐utiles.com/download‐toad‐data‐modeler‐windows‐xp.php . 

 

 

2. Getting started with Toad Data Modeler 

This is the entry screen for Toad Data Modeler.

 

ISOM3260 Lab (Stage 1) 23

Page 24: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 2 of 9 

Step 1. Create a New Model  To get started, a new model should be created first. Select File from menu and then New Model.  

    Step 2: Select the target database  Select Oracle 10g as the target database then press OK to continue. Every  database  has  slightly  different  data definition  language.  This  will  create  the statements specific to Oracle 10g.      

 

Step 3. Prepare to construct ER on the drawing area   A drawing area appears for creating ER Diagrams.  To construct an ERD, use the (1) Entity, (2) Non‐identifying relationship and (3) M:N relationship buttons.  Refer to Appendix 1 about “non‐identifying” relationship    

  

 

ISOM3260 Lab (Stage 1) 24

Page 25: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 3 of 9 

  Step 4. Set display mode  Go to the display mode drop down box and select the display mode as “Entities only” 

   

  Step 5. Construct Entities Click on the entity button and then click on the drawing area to create an entity. 

 

 Step 6. Rename the entity  Double click the entity and rename the Entity Name.   

  

 Step 7. Add attributes into the entity  Define the attribute name and press “Add”.    

 

ISOM3260 Lab (Stage 1) 25

Page 26: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 4 of 9 

Double click the attribute and modify the 

datatype.   

Refer to the table 1 for the appropriate 

datatypes. 

 

 

 

 

 

 

 

 

Table 1. Data format and the corresponding datatypes 

Data Format  Datatype 

Character (eg. Chris Tse; HKUST, etc) VARCHAR2

Numberic (eg. 2000; 10623.48, etc)  NUMBER 

Date (eg. 28 Nov 1987,  10 Oct 2001)  DATE 

 

Step 8. Define the Unique Identifier  Double click “Key” to define Unique Identifier. 

 

   

ISOM3260 Lab (Stage 1) 26

Page 27: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 5 of 9 

 Step 9. Add and configure relationship  Select “Non‐identifying relationship” and then join entities together.  A country may build many cruises. Link the relationship from Country and then drag to Cruise     Set the minimum cardinality of the relationship. Minimum cardinality is the minimum number of instances of one entity that maybe associated with each instance of another entity.        A cruise must be built by at least one country. This is considered as Mandatory.  On the other hand, a country may or may not build a cruise. This is considered as Optional     A crow’s feet preview is shown at the top.          

 

  

ISOM3260 Lab (Stage 1) 27

Page 28: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 6 of 9 

Step 10. Save the model  Upon drawing the ER Diagram, save the model.  

   

 

 

 

ISOM3260 Lab (Stage 1) 28

Page 29: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 7 of 9 

Step 11. Generate DDL for Physical Database creation  Select Generate script under Model.               Select Tables, Primary Keys and Referential Integrity and choose Generate       

 

  

  

ISOM3260 Lab (Stage 1) 29

Page 30: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 8 of 9 

The DDL code for creating physical database is generated,  click view and check out the DDL codes.  

 

   

ISOM3260 Lab (Stage 1) 30

Page 31: database design intro(database)

ISOM 3260 (Spring 2014) Lab 2     Page 9 of 9 

Appendix 1: Identifying and Non‐identifying relationships 

In our lab demonstration, we use non‐identifying relationship, instead of the identifying relationship. 

The following table shows the difference between them 

Relationship Type 

Usage 

Identifying relationship  Being used when the child entity is a weak entity  (unable to uniquely identify every single record without the parent entity) 

Non‐identifying relationship  Being used when the child entity is a strong entity  (able to uniquely identify every single record without the parent entity) 

 

In our class example, the child entities are strong entities, since the records of child entity can be 

identified uniquely using the unique identifier, they are Cruise_no and Staff_no respectively.  

As every single record of the child entities (Cruise and Staff) can be identified without the parent entity 

(Country), we should use non‐identifying relationship for the linkage with Country. 

ISOM3260 Lab (Stage 1) 31

Page 32: database design intro(database)

Checklist for Logical Model in Toad Data Modeler 

Use this checklist to self‐assess the ER Model of your project 

Entity :  ________________________________ 

Checked by :  ___________________________________ 

Items to check  C  NCEntities and Attributes 

1. The entity name is correctly named  

   

2. The attributes names are appropriately named with the short name prefix  STUDENT  STU_ID, STU_ADDRESS..etc  

   

3. The sequence of attributes is defined properly such that identifier (PK) goes first  

   

4. The format of the attributes are correctly set appropriately  Text  VARCHAR2, not CHAR Number (for calculations)  NUMBER Date DATE  

   

5. The maximum length of each attribute is defined logically   You should be able to explain the rationale of setting the maximum number of each attribute  

   

6. The column “Dec” ‐ “Decimal” ‐ is used for numeric attributes only  NUMBER(6,2)  6 digits with 2 decimal places  Max = $9999.99 NUMBER(4,1)  4 digits with 1 decimal places  Max = $999.9 

 

   

7. The primary key/unique identifier of the entity is set appropriately   

   

Relationship 

8. Read the business rules from the ERD again, they are interpreted  the same the draft 

   

 

C = Compliance ; NC = Non‐compliance  

ISOM3260 Lab (Stage 1) 32

Page 33: database design intro(database)

Checklist for Logical Model in Toad Data Modeler 

Use this checklist to self‐assess the ER Model of your project 

Entity :  ________________________________ 

Checked by :  ___________________________________ 

Items to check  C  NCEntities and Attributes 

1. The entity name is correctly named  

   

2. The attributes names are appropriately named with the short name prefix  STUDENT  STU_ID, STU_ADDRESS..etc  

   

3. The sequence of attributes is defined properly such that identifier (PK) goes first  

   

4. The format of the attributes are correctly set appropriately  Text  VARCHAR2, not CHAR Number (for calculations)  NUMBER Date DATE  

   

5. The maximum length of each attribute is defined logically   You should be able to explain the rationale of setting the maximum number of each attribute  

   

6. The column “Dec” ‐ “Decimal” ‐ is used for numeric attributes only  NUMBER(6,2)  6 digits with 2 decimal places  Max = $9999.99 NUMBER(4,1)  4 digits with 1 decimal places  Max = $999.9 

 

   

7. The primary key/unique identifier of the entity is set appropriately   

   

Relationship 

8. Read the business rules from the ERD again, they are interpreted  the same the draft 

   

 

C = Compliance ; NC = Non‐compliance  

   

ISOM3260 Lab (Stage 1) 33

Page 34: database design intro(database)

Checklist for Logical Model in Toad Data Modeler 

Use this checklist to self‐assess the ER Model of your project 

Entity :  ________________________________ 

Checked by :  ___________________________________ 

Items to check  C  NCEntities and Attributes 

1. The entity name is correctly named  

   

2. The attributes names are appropriately named with the short name prefix  STUDENT  STU_ID, STU_ADDRESS..etc  

   

3. The sequence of attributes is defined properly such that identifier (PK) goes first  

   

4. The format of the attributes are correctly set appropriately  Text  VARCHAR2, not CHAR Number (for calculations)  NUMBER Date DATE  

   

5. The maximum length of each attribute is defined logically   You should be able to explain the rationale of setting the maximum number of each attribute  

   

6. The column “Dec” ‐ “Decimal” ‐ is used for numeric attributes only  NUMBER(6,2)  6 digits with 2 decimal places  Max = $9999.99 NUMBER(4,1)  4 digits with 1 decimal places  Max = $999.9 

 

   

7. The primary key/unique identifier of the entity is set appropriately   

   

Relationship 

8. Read the business rules from the ERD again, they are interpreted  the same the draft 

   

 

C = Compliance ; NC = Non‐compliance  

   

ISOM3260 Lab (Stage 1) 34

Page 35: database design intro(database)

Checklist for Logical Model in Toad Data Modeler 

Use this checklist to self‐assess the ER Model of your project 

Entity :  ________________________________ 

Checked by :  ___________________________________ 

Items to check  C  NCEntities and Attributes 

1. The entity name is correctly named  

   

2. The attributes names are appropriately named with the short name prefix  STUDENT  STU_ID, STU_ADDRESS..etc  

   

3. The sequence of attributes is defined properly such that identifier (PK) goes first  

   

4. The format of the attributes are correctly set appropriately  Text  VARCHAR2, not CHAR Number (for calculations)  NUMBER Date DATE  

   

5. The maximum length of each attribute is defined logically   You should be able to explain the rationale of setting the maximum number of each attribute  

   

6. The column “Dec” ‐ “Decimal” ‐ is used for numeric attributes only  NUMBER(6,2)  6 digits with 2 decimal places  Max = $9999.99 NUMBER(4,1)  4 digits with 1 decimal places  Max = $999.9 

 

   

7. The primary key/unique identifier of the entity is set appropriately   

   

Relationship 

8. Read the business rules from the ERD again, they are interpreted  the same the draft 

   

 

C = Compliance ; NC = Non‐compliance  

 

ISOM3260 Lab (Stage 1) 35

Page 36: database design intro(database)

2. Checklist for Physical Tables in SQLTools 

Use this checklist to self‐assess the physical tables of your project 

Items to check  C  NCTables 

1. The tables are created in the database, and they are consistent with your physical design  Execute  SELECT table_name  FROM user_tables;  

   

2. The metadata of every attribute in the table are consistent with your physical design 

 Execute  SELECT column_name, data_type, data_length FROM user_tab_columns WHERE table_name=‘STUDENT’;  

   

3. The constraints of every table are consistent with your physical design  Execute SELECT constraint_name, constraint_type, search_condition  FROM user_constraints  WHERE table_name=‘STUDENT’;  

   

 

 

ISOM3260 Lab (Stage 1) 36

Page 37: database design intro(database)

3/1/13 Exploring Database Design Tips - For Dummies

www.dummies.com/how-to/content/exploring-database-design-tips.html 1/3

Advertisement

Agoda's Best Hotel Offers Save up to 75% Instant confirmation Book now! Agoda.com/Hotels

CEF Approved Courses Excel and VBA for business modeling Create and manage Access databases www.welkin.com.hk

Free Hyper-V Backup Easy to use Hyper-V backup software Free for 2 VMs, forever. No catch. www.altaro.com/free-hyper-v-backup/

Visitor Management System Guess Pre-Registration for Event, Online Counter Register & Reports. www.rentech.asia

Exploring Database Design TipsBy Doug Lowe from ASP.NET 2.0 Everyday Apps For Dummies

One of the most important aspects of any application-development project is the database design. And so, without further ado,here are some tips for designing good databases.

Use the right number of tables

In Amadeus, the Emperor of Germany criticizes one of Mozart's works as having "too many notes." Mozart replies indignantly that

he uses neither too many nor too few notes, but the exact number of notes that the composition requires.

So it should be with database design. Your database should have as many tables as the application requires — not more, not

fewer. There is no single "right" number of tables for all databases.

Inexperienced database designers have a tendency to use too few tables — sometimes trying to cram an entire database-worth

of information into a single table. At the other extreme are databases with dozens of tables, each consisting of just a few fields.

Avoid repeating data

One of the core principles of relational database design is to handle repeating data by breaking it out into a separate table. Forexample, in the old days of flat-file processing, it was common to create invoice records that had room for a certain number of

line items. Thus the invoice record would have fields with names like Item1, Item2, Item3, and so on.

Bad!

Whenever you find yourself numbering field names like that, you should create a separate table. In the case of the invoice record,

you should create a separate table to store the line item data.

Avoid redundant data

When designing the tables that make up your database, try to avoid creating redundant data. Whenever redundant data creeps

into a database, it introduces the likelihood that the data will become corrupt. For example, suppose you store a customer'sname in two different tables. Then, if you update the name in one of the tables but not the other, the database has becomeinconsistent.

The most obvious type of redundant-data mistake is to create a field that exists in two or more tables. But there are more subtle

types of redundant data. For example, consider an Invoice table that contains a LineItemTotal field that represents the sum of

the Total fields in each of the invoice's line items. Technically, this field represents redundant data; the data is also stored in the

Total fields of each line item.

Whether you should allow this type of redundancy depends on the application. In many cases, it's better to put up with the

redundancy for the convenience and efficiency of not having to recalculate the total each time the data is accessed. But it's

always worth considering whether the added convenience is worth the risk of corrupting the data.

Use a naming convention

To avoid confusion, pick a naming convention for your database objects and stick to it. That way your database tables, columns,

constraints, and other objects will be named in a consistent and predictable way. (Just think of the savings on aspirin.)

You can argue from now until St. Swithen's day about what the naming conventions should be. That doesn't matter so much. Whatdoes matter is that you make a convention — and follow it.

Avoid nulls

Allowing nulls in your database tables significantly complicates the application programming required to access the tables. As aresult, avoid nulls by specifying NOT NULL whenever you can. Use nulls rarely, and only when you truly need them.

ISOM3260 Lab (Stage 1) 37

http://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.dummies.com/how-to/content/exploring-database-design-tips.html%26gl%3DHK%26hl%3Den%26client%3Dca-pub-8905085009868771%26ai0%3DCmhPsz74wUZesB86-6gHYioHACNa_h8IE9pzqll6OhuKDRRABIOa86hcoBFCVh7yl-P____8BYNkCoAGy5ObVA8gBAagDAcgDnwSqBJkBT9DuNK6TVX00_2y39TyLXh9-91SBI6NBHTeYlMkfS7nKM_QsVc8SyPRvoA-Jp2iGkMC4QRzE9h4E3hRb5TgPNNeqT6zieBN1WMG78BzI_Z9VNY9iGeoP5k8fAreqm5clTnxle56VnKW_gFs3ajSXVQufWjt0L9CzVjlR95ntM8Ks7q8jQhXELVRmkOqSethBc9bT2pkLqfwJiAYBgAe2m5kq%26ai1%3DCT1hNz74wUZesB86-6gHYioHACJvyzqgCi8rMozjAjbcBEAIg5rzqFygEUIbJm58CYNkCoAHh9rj6A8gBAakCL_l1GHxOgT6oAwHIA58EqgSQAU_Q7gKtllV-NP9st_U8i14ffvdUgSOjQR03mJTJH0u5yjP0LFXPEsj0b6APiadohpDAuEEcxPYeBN4UW-U4DzTXqk-s4ngTdVjBu_AcyP2fVTWPYhnqD-ZPHwK3qpuXJU58ZXuelZylv4BbN2o0l1ULn1o7dC_Qm1frmwAsMezbBBh7IbcW1OFQJ4Xvacc2V4gGAYAHh4nHBQ%26ai2%3DCTKOWz74wUZesB86-6gHYioHACL391IgD7ce3qU3Bu7y1FxADIOa86hcoBFCi7ZXm______8BYNkCoAGqkIv_A8gBAagDAcgDnwSqBJEBT9CeG3uPTkQMTd-5jTyLB1Vv71SFL7UcUDuaQ3IXdbzAc7UlOvEAYS8ngROJoyKTkJi4QUWO5wYE2hhNuHUDNpXtSLS4IQg1FM266g3D58QfKId-GvcU4UZVS7K_jpQmXGotMp-Dhqu2wwIqczfKExeGW9f2LBFxUNSaIi3E69tA7TjUtBbEKUTuYehyfHaHjIgGAYAHvu90%26ai3%3DCMPHXz74wUZesB86-6gHYioHACJC2lb0CuNTglCzAjbcBEAQg5rzqFygEUKyL1bAFYNkCyAEBqQIv-XUYfE6BPqgDAcgDnwSqBI0BT9C-dv-WVXg0_2y39TyLXh9-91SBI6NBHTeYlMkfS7nKM_QsVc8SyPRvoA-Jp2iGkMC4QRzE9h4E3hRb5TgPNNeqT6zieBN1WMG78BzI_Z9VNY9iGeoP5k8fAreqm5clTnxle56VnKW_gFs3ajSXVQufWjscLgZxoT-Z8S9xHdhE7XgxfxLFyVLE-GCYgAfqqOkK&usg=AFQjCNHEBDisFEJYoQUxdwBQeb9ul9WLeg
Page 38: database design intro(database)

3/1/13 Exploring Database Design Tips - For Dummies

www.dummies.com/how-to/content/exploring-database-design-tips.html 2/3

Dummies Recommends

Knowing Just Enough about RelationalDatabases

The Long and the Short of Coat Styles

for Your Yorkshire Terrier

How to Design a Relational Database in

Access 2010

Secrets of Access 2010 Database

Design

Getting a Look At Web Services

From Around the Web

Free tool by Microsoft helps identify andzap malware (TechNet)

6 Things You Don't Know About Content

Marketing (King Content)

Kaazing Publishes First Definitive

Guide to HTML5 WebSocket (dlvr.it)

Making Your Home Less Cluttered (Live

Smarter)

The Gmail Add-On You Must Have(Inc.com)

Nulls are often misused anyway. The correct use of null is for a value that is unknown; not for a blank or empty value. For example,consider a typical address record that allows two address lines, named Address1 and Address2. Most addresses have only oneaddress, so the second address line is blank. The value of this second address line is, in fact, known — it's blank. That's not thesame thing as null. Null would imply that the address may have a second address line; we just don't know what it is.

Even for columns that might seem appropriate for nulls, it's usually more convenient to just leave the column value blank for valuesthat aren't known. For example, consider a phone number column in a Customer table. It's safe to assume that all yourcustomers have phone numbers, so it would be correct to use null for phone numbers that you don't know. However, from apractical point of view, it's just as easy to disallow nulls for the phone number column, and leave the unknown phone numbersblank.

Avoid secret codes

Avoid fields with names like CustomerType, where the value of the field is one of several constants that aren't defined elsewherein the database, such as R for Retail or W for Wholesale. You may have only these two types of customers today, but the needsof the application may change in the future, requiring a third customer type.

An alternative would be to create a separate table of customer-type codes (call it CustomerTypes), and then create a foreign-keyconstraint so the value of the CustomerType column must appear in the CustomerTypes table.

Use constraints wisely

Constraints let you prevent changes to the database that violate the internal consistency of your data. For example, a checkconstraint lets you validate only data that meets certain criteria. For example, you can use a check constraint to make sure the

value of a field named Price is greater than zero.

A foreign-key constraint requires that the value of a column in one table must match the value that exists in some other table. For

example, if you have a LineItems table with a column named ProductID, and a Products table with a column also named

ProductID, you could use a foreign-key constraint to make sure that the ProductID value for each row in the LineItems table

matches an existing row in the Products table.

Use triggers when appropriate

A trigger is a procedure that kicks in when certain database data is updated or accessed. Triggers are a great way to enforce

those database rules that are more complicated than simple constraints. For example, suppose an Invoice table contains anItemCount column whose value is the number of line items for the invoice. One way to maintain the value of this column

automatically would be to create triggers that increment the ItemCount column whenever a line item is inserted, and decrementthe ItemCount column whenever a line item is deleted. Sometimes automation is a beautiful thing.

Use stored procedures

Stored procedures are SQL procedures that are tucked away in the database and are part of it. There are several advantages to

using stored procedures instead of coding SQL in your applications:

Using stored procedures removes the burden of SQL programming from your application programmers. Instead, it makes

the SQL used to access the database a part of the database itself — no fuss, no muss. All the application programs have to

do is call the appropriate stored procedures to select, insert, update, or delete database data.

Stored procedures are more efficient as a way of handling transactions, because the database server handles the entire

transaction.

Stored procedures are also more efficient because they reduce the amount of network traffic between the database server

and the Web server.

Finally, stored procedures are more secure because they reduce the risk of SQL injection attacks.

ISOM3260 Lab (Stage 1) 38

Page 39: database design intro(database)

3/1/13 Exploring Database Design Tips - For Dummies

www.dummies.com/how-to/content/exploring-database-design-tips.html 3/3

How To Take Great Photos With Your

DSLR Camera (Inkling)

Recommended by

Copyright © 2013 & Trademark by John Wiley & Sons, Inc. All rights reserved.

ISOM3260 Lab (Stage 1) 39

Page 40: database design intro(database)

 

ISOM3260 Spring 2014 Lab 2 Class Practice      Page 1 of 1  

Class Exercise: 

(1) Use Toad Data Modeler to create a ER diagram of a database extract for Spirit Cruise Line. 

This extract consists of three tables and two non‐identifying relationships. 

 

Table: CRUISE 

Attribute Name  Datatype 

*CRUISE_NO  VARCHAR2 

CRUISE_NAME  VARCHAR2 

YEAR_BUILT  VARCHAR2 

DISPLACEMENT  NUMBER 

SPEED  NUMBER 

ROOM  NUMBER 

PASSENGER  NUMBER 

 

Table: COUNTRY 

Attribute Name  Datatype 

*COUNTRY_CODE  VARCHAR2 

COUNTRY_NAME  VARCHAR2 

 

Table: STAFF 

Attribute Name  Datatype 

*STAFF_NO   VARCHAR2 

LAST_NAME  VARCHAR2 

FIRST_NAME  VARCHAR2 

SEX  VARCHAR2 

ADDRESS  VARCHAR2 

DOB  DATE 

D_ENTRY  DATE 

SALARY  NUMBER 

 

Note:  

The attributes with asterisk (*) are unique identifiers.  

All the entities here are strong entities, hence “Non‐identifying Relationship” is used 

Business Rules: 

(1) Each staff is from one country only, and there is more than one staff from the same 

country. 

(2) Each ship is built in one country only, and there is more than one ship being built in 

the same country. 

 

ISOM3260 Lab (Stage 1) 40

Page 41: database design intro(database)

ISOM3260 (Spring 2013) Supplementary Notes 1  Page 1 of 1  

Supplementary Notes 1:  Reserved Words in Oracle Database 11g 

The following words are reserved by Oracle. That is, they have a special meaning to Oracle and so cannot be redefined. For this reason, you cannot use them to name database objects such as columns, tables, or indexes. (extracts from Oracle® Database Programmer's Guide to the Oracle Precompilers 11g Release 2) 

ACCESS  ELSE  MODIFY  START 

ADD  EXCLUSIVE  NOAUDIT  SELECT 

ALL  EXISTS  NOCOMPRESS  SESSION 

ALTER  FILE  NOT  SET 

AND  FLOAT  NOTFOUND  SHARE 

ANY  FOR  NOWAIT  SIZE 

ARRAYLEN  FROM  NULL  SMALLINT 

AS  GRANT  NUMBER  SQLBUF 

ASC  GROUP  OF SUCCESSFUL 

AUDIT  HAVING  OFFLINE  SYNONYM 

BETWEEN  IDENTIFIED ON SYSDATE 

BY  IMMEDIATE  ONLINE  TABLE 

CHAR  IN  OPTION THEN 

CHECK  INCREMENT  OR  TO 

CLUSTER  INDEX  ORDER  TRIGGER 

COLUMN  INITIAL  PCTFREE  UID 

COMMENT  INSERT  PRIOR UNION 

COMPRESS  INTEGER  PRIVILEGES  UNIQUE 

CONNECT  INTERSECT  PUBLIC  UPDATE 

CREATE  INTO  RAW  USER 

CURRENT  IS  RENAME  VALIDATE 

DATE  LEVEL  RESOURCE  VALUES 

DECIMAL  LIKE  REVOKE VARCHAR 

DEFAULT  LOCK  ROW  VARCHAR2 

DELETE  LONG  ROWID VIEW 

DESC  MAXEXTENTS  ROWLABEL  WHENEVER 

DISTINCT  MINUS  ROWNUM WHERE 

DROP  MODE  ROWS  WITH 

 

ISOM3260 Lab (Stage 1) 41

Page 42: database design intro(database)

ISOM3260 Database Design and Administration

Lab 3: Oracle Forms Developer I

A real example of “Line Item”

ORDER_INFOEach order (sales memo) containsthe description such as…

SHOP_ID, Date, Staff, Memo_ID, Order Total and Credit card number

Each order (sales memo) must haveat least 1, to multiple “PURCHASE ITEM”to be stored in a separate entity

ISOM3260 Lab (Stage 1) 42

Page 43: database design intro(database)

ORDER_INFO

Memo_ID

Date Cashier … Order_Total

Credit Card

CP8‐01‐018965 (1)

17/2/201313:26:14

09913 … 2976 XXXXXXX2003

… … … … … …

CP8‐01‐018981 (1)

18/2/201309:10:12

09176 … 576 XXXXXXXX0011

… … … … … …

ORDER_DETAIL

Detail_ID

Memo_ID

Line Pdt_ID List_Price

Qty Subtotal

00401 CP8‐01‐018965 (1)

1 LBR410 1899 1 1350

00402 CP8‐01‐018965 (1)

2 BUX410 1599 1 1120

00403 CP8‐01‐018965 (1)

3 CHX390 1499 1 1050

… … … … … … …

00468 CP8‐01‐018981 (1)

1 ABC111 600 1 576

Each Order  __________(must/may) have one to many details

ISOM3260 Lab (Stage 1) 43

Page 44: database design intro(database)

Agenda

Oracle Project

Analysis, DesignImplementation, Maintenance

Oracle Forms Developer

SQL ToolsOracle Reports Developer

Oracle Application Integration

Learning objectives:

• Understand the 3 components in Forms Developer

– Data Block, Canvas, Module

• Build 2 simple pages in Oracle Forms 

• Understand a major use of “Trigger”

• Practice the procedures of writing GO_BLOCK triggers, compile the program and perform runtime

ISOM3260 Lab (Stage 1) 44

Page 45: database design intro(database)

Oracle Forms Developer

– Develop front‐end applications in Graphical User Interface (GUI)

– Insert/delete/edit/view records in the database, without any knowledge of database design and SQL statements

– Programming Language: PL/SQL

Components in Forms Developer

• Data Block

– A set of “objects” on a page (Textboxes, Buttons, pull down menu, etc)

• Canvas

– A “page” 

– A normal canvas has at least one, or more than one datablock

• Module

– A whole system

ISOM3260 Lab (Stage 1) 45

Page 46: database design intro(database)

Components in Forms Developer

Datablocks

Object Navigator shows all componentsof a “module”

Canvases

Class Exercise

• In this lab, we are going to build simple pages in Oracle Forms

Datablock: WELCOMECanvas: WELCOME_C

Datablock: CUST_LOGINCanvas: CUST_LOGIN_C

ISOM3260 Lab (Stage 1) 46

Page 47: database design intro(database)

Prerequisite Settings (1) 

• In order to loose the Oracle Forms Developer’s default control, change the validation unit to “Form”

• Do this prerequisite setting to your Project File

Prerequisite Settings (2) MUST SET !!!

Change the Validation Unit into “Form”

ISOM3260 Lab (Stage 1) 47

Page 48: database design intro(database)

Steps to create a page in Oracle Forms

Step 1: Create a new canvas 

Select “Canvases” and click “Create”

Steps to create a page in Oracle Forms

Step 2: Rename the canvas

To be systematic, rename the canvas using this format:

<canvas name> _C

eg. WELCOME_C , LOGIN_C, etc.

ISOM3260 Lab (Stage 1) 48

Page 49: database design intro(database)

Steps to create a page in Oracle Forms

Step 3: Create a new data block

a. Select “Datablocks” and click “Create”

b. In the pop‐up windows, choose “Build a new data block manually” and click OK

Steps to create a page in Oracle Forms

Step 4: Rename a new data block

ISOM3260 Lab (Stage 1) 49

Page 50: database design intro(database)

Steps to create a page in Oracle Forms

Step 5: Open Layout Editor

a. Right click the datablock, and choose “Layout Editor”

b. “Layout Editor” is shown for creating a page

Steps to create a page in Oracle FormsStep 6: Select the correct datablock and start adding “Objects” – Button, Text, Checkboxes, Radio groups, etc.

ISOM3260 Lab (Stage 1) 50

Page 51: database design intro(database)

Trigger

• A series of actions written in PL/SQL

• Usually written in a button

• Event‐driven, execute when a certain action takes place:

Most common: WHEN‐BUTTON‐PRESSED

Switching among canvases

• When user clicks “Customer” button, the login page is shown…

• GO_BLOCK (‘Datablock Name’);

– Not Canvas Name

GO_BLOCK(‘CUST_LOGIN’);

GO_BLOCK(‘WELCOME’);

ISOM3260 Lab (Stage 1) 51

Page 52: database design intro(database)

Write a PL/SQL trigger in the push button (1)

• Write PL/SQL trigger in “PL/SQL Editor”

Write a PL/SQL trigger in the push button (2)

• Select a trigger event –

WHEN‐BUTTON‐PRESSED

ISOM3260 Lab (Stage 1) 52

Page 53: database design intro(database)

Write a PL/SQL trigger in the push button (3)

• Write a PL/SQL trigger in the PL/SQL Editor

Write a PL/SQL trigger in the push button (4)

• Press “Compile PL/SQL Code” to compile

ISOM3260 Lab (Stage 1) 53

Page 54: database design intro(database)

Write a PL/SQL trigger in the push button (5)

• Start OC4J Instance

Write a PL/SQL trigger in the push button (6)

• Press “Run Form” to load the Forms

ISOM3260 Lab (Stage 1) 54

Page 55: database design intro(database)

Summary:

• Understand the 3 components in Forms Developer

– Data Block, Canvas, Module

• Build 2 simple pages in Oracle Forms 

• Understand a major use of “Trigger”

• Practice the procedures of writing GO_BLOCK triggers, compile the program and perform runtime

ISOM3260 Lab (Stage 1) 55

Page 56: database design intro(database)

ISOM3260 Database Design and Administration

Lab 4: Oracle Forms Developer II –

insert records into database

1

Agenda

Oracle Project

Analysis, DesignImplementation, Maintenance

Oracle Forms Developer

SQL ToolsOracle Reports Developer and integration

2

ISOM3260 Lab (Stage 1) 56

Page 57: database design intro(database)

Agenda

• Location of objects 

• Build a page to insert student information

• Project Work

3

Understand the Components in Oracle Forms

• Open Lab4.fmb in Oracle Forms Developer 

• Object Navigator

4

ISOM3260 Lab (Stage 1) 57

Page 58: database design intro(database)

Recap:Components in Forms Developer

• Data Block

– A set of “objects” on a page (Textboxes, Buttons, pull down menu, etc)

• Canvas

– A “page” 

– A normal canvas has at least one, or more than one datablock

• Module

– A whole system

5

1 Module: LAB4

1 Datablock - STUDENT_INSERT

1 Canvas- STUDENT_INSERT_C

Take a look at “STUDENT_INSERT_C” by choosing “Layout Editor”

6

ISOM3260 Lab (Stage 1) 58

Page 59: database design intro(database)

Canvas: STUDENT_INSERTE_C(A page in an information systems)

Datablock: STUDENT_INSERT

(Textboxes created base on the columns in table “STUDENTS”)

Buttons (contains Trigger) :BTN_INSERT(Created under the datablock “STUDENT_INSERT)

7

Location of Objects

• The locations of different objects (eg. textboxes) are crucial in PL/SQL programming: 

– Capture textbox values for inserting data

– Retrieve data from database to corresponding textboxes

: <Datablock Name> . <Object Name>

8

ISOM3260 Lab (Stage 1) 59

Page 60: database design intro(database)

• Click on individual objects (textboxes, buttons) and locate them

For example: The location of the textbox “STUDENT_NAME” is

:STUDENT_INSERT.STUDENT_NAME9

Exercise on Location of Textboxes

10

ISOM3260 Lab (Stage 1) 60

Page 61: database design intro(database)

Demonstration : 

Build a page to insert student information

11

Build a page to insert student information

• Close Lab4‐stu.fmb in Oracle Forms Developer and create a new Module 

• Build a datablock with columns base on the table ‐ STUDENTS 

• Build a canvas and lay out the datablock

12

ISOM3260 Lab (Stage 1) 61

Page 62: database design intro(database)

Prerequisite Settings (1) 

• In order to loose the Oracle Forms Developer’s default control, change the validation unit to “Form”

• Do this prerequisite setting to your Project File

13

Prerequisite Settings (2) MUST SET !!!

Change the Validation Unit into “Form”

14

ISOM3260 Lab (Stage 1) 62

Page 63: database design intro(database)

A customer record

15

ylx008

******

******

[email protected]

Peter

Johnson

CUS_ID CUS_LName CUS_FName CUS_UID CUS_PWD CUS_Email

C0001 Johnson Peter ylx008 ****** [email protected]

C0002 Alex Ng ang098 ****** [email protected]

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

After user presses “Signup”, a customer record is created in the customer table

Datablock Wizard (1)

• Create a datablock using Datablock Wizard

16

ISOM3260 Lab (Stage 1) 63

Page 64: database design intro(database)

Datablock Wizard (2)

Create a datablock base on Table or View

17

Datablock Wizard (3)

• Click Browse and login to your Oracle account 

• Username : lab5

• Password : lab5

• Database: imz350

18

ISOM3260 Lab (Stage 1) 64

Page 65: database design intro(database)

Datablock Wizard (4)

• Select the tables of which the datablock is based on

(i.e. STUDENTS)

19

Datablock Wizard (5)

• Select the columns that the datablock to include (usually pick all)

• Then, the datablock is going to contain 4 items, which based on the 4 columns in table STUDENTS

20

ISOM3260 Lab (Stage 1) 65

Page 66: database design intro(database)

Datablock Wizard (6)

• Modify the Datablock Name

• Do NOT use the default name

– Make it easier to distinguish

21

Datablock Wizard (7)

• Press Finish and Layout Wizard is going to launch

22

ISOM3260 Lab (Stage 1) 66

Page 67: database design intro(database)

Layout Wizard (1)

• Select a canvas that you want to put the datablock on

23

Layout Wizard (2)

• Select all the items of “STUDENT_INSERT” datablock to display

24

ISOM3260 Lab (Stage 1) 67

Page 68: database design intro(database)

Layout Wizard (3)

• You may want to change the “Prompt” and make them look more user‐friendly

(e.g. Stu_id Student ID)

25

Layout Wizard (4)

• There are two kinds of layout style of a datablock– Form is for singular record

– Tabular is for multiple records

26

ISOM3260 Lab (Stage 1) 68

Page 69: database design intro(database)

Layout Wizard (5)

• Press Finish to complete the Layout Wizard

27

Design the Canvas

A canvas is created

Modify the outlook/font size/font face 

28

ISOM3260 Lab (Stage 1) 69

Page 70: database design intro(database)

Design the Canvas

29

Write a trigger to insert records to the database

• Insert a push button “Insert”

• Write a PL/SQL trigger in the push button

– When the button is pressed, the values of the 4 textboxes will be inserted to Student table in database

30

ISOM3260 Lab (Stage 1) 70

Page 71: database design intro(database)

Insert a push button

• Create a push button “Insert”31

Write a PL/SQL trigger in the push button (1)

• Write PL/SQL trigger in “PL/SQL Editor”

32

ISOM3260 Lab (Stage 1) 71

Page 72: database design intro(database)

Write a PL/SQL trigger in the push button (2)

• Select a trigger event –

WHEN‐BUTTON‐PRESSED

33

Write a PL/SQL trigger in the push button (3)

• Write a PL/SQL trigger in the PL/SQL Editor34

ISOM3260 Lab (Stage 1) 72

Page 73: database design intro(database)

PL/SQL Code for inserting Student Records

BEGININSERT INTO student VALUES

(:student_insert.student_id,

:student_insert.student_name,

:student_insert.email,

:student_insert.year);

35

PL/SQL Code for inserting Student Records

BEGININSERT INTO student VALUES

(:student_insert.student_id,

:student_insert.student_name,

:student_insert.email,

:student_insert.year);

36

ISOM3260 Lab (Stage 1) 73

Page 74: database design intro(database)

PL/SQL Code for inserting Student Records

BEGININSERT INTO student VALUES

(:student_insert.student_id,

:student_insert.student_name,

:student_insert.email,

:student_insert.year);

37

PL/SQL Code for inserting Student Records

BEGININSERT INTO student VALUES

(:student_insert.student_id,

:student_insert.student_name,

:student_insert.email,

:student_insert.year);

38

ISOM3260 Lab (Stage 1) 74

Page 75: database design intro(database)

PL/SQL Code for inserting Student Records

message(‘The student ’ || :STUDENT_INSERT.Student_Name || ‘ is inserted’);A message prompt shows The student XXX is inserted|| means concatenation

forms_ddl('Commit');

VERY IMPORTANT!! Use this command to save the record permanently in the database!!!

End;

39

Write a PL/SQL trigger in the push button (4)

• Press “Compile PL/SQL Code” to compile

40

ISOM3260 Lab (Stage 1) 75

Page 76: database design intro(database)

Write a PL/SQL trigger in the push button (5)

• Start OC4J Instance

41

Write a PL/SQL trigger in the push button (6)

• Press “Run Form” to load the Forms

42

ISOM3260 Lab (Stage 1) 76

Page 77: database design intro(database)

Write a PL/SQL trigger in the push button (7)

• Input a student record as you were the system user

• Press Insert to insert the record into the database

43

Write a PL/SQL trigger in the push button (8)

• Check the results in SQL Tools

44

ISOM3260 Lab (Stage 1) 77

Page 78: database design intro(database)

Generate unique ID for records

45

ylx008

******

******

[email protected]

Peter

Johnson

CUS_ID CUS_LName CUS_FName CUS_UID CUS_PWD CUS_Email

C0001 Johnson Peter ylx008 ****** [email protected]

C0002 Alex Ng ang098 ****** [email protected]

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

When a new record is inserted, a new ID will be generated sequentially.

The new ID is generated using an IF statement.

Summary

• Identify location of textboxes

:<Datablock Name> . <Object Name>

• Create Oracle Forms user interfaces to insert records in the database

• Generate unique ID for records in database

46

ISOM3260 Lab (Stage 1) 78

Page 79: database design intro(database)

Project Work

• Do the following coding for your project:

Member/Customer:

• Member registration (i.e. insert member information)

Staff:

• Insert Product Information

47

ISOM3260 Lab (Stage 1) 79

Page 80: database design intro(database)

ISOM3260 Lab

 4 – Object Lo

cation Exe

rcise  

  

  

 Page 1

 of 1

   Write d

own th

e locatio

n of th

e objects (Te

xtboxes an

d Butto

ns) 

ISOM

3260 Lab (Stage 1)80

Page 81: database design intro(database)

Page 1 of 3  

1. Insert statements 

BEGIN 

‐‐INSERT statements 

INSERT INTO student VALUES  

(:student_insert.student_id,  

:student_insert.student_name,  

:student_insert.email,  

:student_insert.year); 

 

‐‐Display a message upon the insertion 

Message('Student ' || :student_insert.student_name || ' has been created.'); 

 

‐‐Save the new record to the table 

forms_ddl('Commit'); 

END; 

   

ISOM3260 Lab (Stage 1) 81

Page 82: database design intro(database)

Page 2 of 3  

2. Select Statements 

BEGIN 

 

‐‐SELECT statements 

SELECT student_name, email, STUDENT.year 

INTO :student_edit.student_name, 

:student_edit.email, 

:student_edit.year 

FROM student 

WHERE student_id=:student_edit.student_id; 

 

END;   

 

   

ISOM3260 Lab (Stage 1) 82

Page 83: database design intro(database)

Page 3 of 3  

3. Update Statements 

BEGIN 

‐‐UPDATE statements 

UPDATE student SET student_id=:student_edit.student_id, 

student_name=:student_edit.student_name,  

email=:student_edit.email, 

student.year=:student_edit.year 

WHERE student_id=:student_edit.student_id; 

‐‐Display a message upon the edition 

Message('Student '||:student_edit.student_name||' has been updated.'); 

‐‐Save the edited record to the table  

forms_ddl('Commit'); 

END; 

ISOM3260 Lab (Stage 1) 83

Page 84: database design intro(database)

Lab 4: Generate Unique ID in the table  Suppose I have a table NUMBERING with an ID NUMBER(5), and the ID should be generated sequentially from 1 to 99999. To generate a unique ID sequentially when I insert a new record, we use the following code : 

DECLARE -- Current_Number is the variable that stores the current number of records in the table -- New_number is the variable that stores the current number of records in the table “ + 1” current_number number(10); new_number number(10); BEGIN -- Select the counted number of records from the table, assign it into the variable -- current_number select max(id) into current_number from numbering; new_number:=current_number+1;

-- INSERT statement that inserts the new_id in the numbering table, and commit insert into numbering values (new_number); forms_ddl('commit'); end;

ISOM3260 Lab (Stage 1) 84

Page 85: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 1 of 6 

Supplementary Note 2: DATE format in Oracle Database and Oracle Forms 

Note the SQL syntax when inserting records with DATE format into the Oracle Database using SQL. For example, a table –DAY is created with the following metadata: 

TABLE: DAY 

Attribute  Data Type 

ID  VARCHAR2 (3) 

DOB  DATE 

1. Insert Date into Oracle Database using SQLTools 

The syntax of inserting a record ‘001, 24/3/2010’ is  

INSERT INTO DAY VALUES (‘001’,’24-MAR-2010’);

However, an error message maybe appeared – ORA01843 Not a valid month. This is due to the locale of your computer. To solve this problem, execute the following statement before inserting records with DATE format: 

ALTER session SET nls_date_language='american';

Note that the DATE format in Oracle contains not only date, but time as well. Without specifying the time, the default value is 00:00:00.  

In the example above, while date is inserted as 24‐MAR‐2010, the value actually is 24‐MAR‐2010 12:00:00am. 

ISOM3260 Lab (Stage 1) 85

Page 86: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 2 of 6 

2. Insert Date and Time into Oracle Database using SQLTools 

To insert date and time together, we use a function called “TO_DATE”.   

The syntax of inserting a record ‘002, 24/3/2010 12:01:00’ is 

INSERT INTO DAY VALUES(‘002’,TO_DATE('2010/03/24:12:01:00', ‘yyyy/mm/dd:hh24:mi:ss'));

 

ISOM3260 Lab (Stage 1) 86

Page 87: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 3 of 6 

3. Insert Current Date and Time into Oracle Database 

We can insert the current date and time into the Oracle Database, the effect is equivalent to using TIMESTAMP in other databases. 

‘SYSDATE’ is used for showing the current date and time of the Oracle Server. For your interest, you may execute the below SQL statement and see the values of the current date and time. 

SELECT sysdate FROM dual;

Note that the current time and date depends on the Oracle Server, not your computer. 

The syntax of inserting a record ‘004, <Current Time>’ is 

INSERT INTO DAY VALUES(‘004’, sysdate); sysdate includes time (Hours, Minutes and second). Occasionally, instead of keeping current time, you may want to insert system date only.  The syntax of inserting a record, ‘005, <Current Date>’ is 

INSERT INTO DAY VALUES(‘005’, to_date(to_char(sysdate,’DDMMYYYY’), ‘DDMMYYYY’));

ISOM3260 Lab (Stage 1) 87

Page 88: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 4 of 6 

4. Write triggers to obtain DATE value from user interface 

You should change the format of the textbox (generated from Datablock wizard) into CHAR format from DATE format.  

When writing a trigger to insert data into database, use “TO_DATE” function to convert users’ input from VARCHAR2 format into DATE format before inserting it into database. 

 

begin

insert into day values (:date.date_id, to_date(:date.dob, ‘DD/MM/YYYY'));

forms_ddl('commit');

end;

ISOM3260 Lab (Stage 1) 88

Page 89: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 5 of 6 

5. Setting up format mask of displaying DATE format in Oracle Forms  The format of displaying DATE fields in Oracle Forms depends on the locale of the computer. For instance, if your computer is configured with a traditional Chinese locale, then the current date will be “24‐三月‐2010”. However, if your computer is configured with an English locale, then the current date 

will be “24‐MAR‐2010”.  In order to overcome the problems of different location settings among computers, we set up format mask in order to unify the display/input format. 

 To specify the Format Mask in a DATE field, Right click and choose Property Palette.  

 Set Format Mask as DD‐MM‐YYYY, so that users, no matter which locales they are using, input Date of Birth as ‘01‐01‐1988’, instead of ‘01‐JAN‐1988’ or ’01‐一月‐1988’. 

ISOM3260 Lab (Stage 1) 89

Page 90: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 2                                                                               Page 6 of 6 

Appendix 1: Format Masks to be used in TO_DATE and TO_CHAR functions  

Format  Meaning 

YYYY  Year 

MM  Month 

DD  Day of month 

DDD  Day of year 

D  Day of week 

DY  Abbreviation of day, eg. MON 

Q  Quarter of year 

HH  Hour of day 

HH24  24 hours representation 

MI  Minutes 

SS  Seconds 

SSSSS  Number of seconds since mid‐night  

ISOM3260 Lab (Stage 1) 90

Page 91: database design intro(database)

ISOM3260 Spring 2014 Supplementary Note 4                                                                                   Page 1 of 1 

Supplementary Notes 4 : Configure Multiple lines with Scroll Bar in a field 

Sometimes the fields to display are long that you need skipping lines, or even a scroll bar is needed. For instance, Address of the member, description of the book, etc. Configure as follow:  

Step 1 

Right  Click  the  Text  Item  and  Choose Property Palette 

Set the following item as Yes 

‐ Multi‐line ‐ Show Vertical Scroll Bar 

 

 

Step 2 

The actual result will be shown only when you run Form. 

 

 

 

ISOM3260 Lab (Stage 1) 91

Page 92: database design intro(database)

ISOM3260 Database Design and Administration

Lab 5: Oracle Forms Developer III –retrieve/update records into database and 

validation trigger

1

Agenda

Oracle Project

Analysis, DesignImplementation, Maintenance

Oracle Forms Developer

SQL ToolsOracle Reports Developer and integration

2

ISOM3260 Lab (Stage 1) 92

Page 93: database design intro(database)

Learning Objectives:

• Examine the PL/SQL code to retrieve Student records

• Understand 5 common error codes in Oracle

• Apply PL/SQL code to retrieve and update Student records

• Understand the need of validation triggers

• Apply different kinds of validation triggers for project

3

RecapInsert student records

4

ISOM3260 Lab (Stage 1) 93

Page 94: database design intro(database)

RecapStudent Table in database

5

Examine the code of retrieving Students Record

• Open Lab5‐stu.fmb in Oracle Forms Developer 

• Right click “Student_Retrieve_C” and choose Layout editor

6

ISOM3260 Lab (Stage 1) 94

Page 95: database design intro(database)

Show the PL/SQL code of Retrieve button

7

PL/SQL Code for retrieving Student Records

SELECT student_name, email, year

INTO :student_edit.student_name, :student_edit.email, :student_edit.year 

FROM student 

WHERE student_id=:student_edit.student_id;

8

ISOM3260 Lab (Stage 1) 95

Page 96: database design intro(database)

PL/SQL Code for retrieving Student Records

SELECT student_name, email, year

Choose to print the 3 fields 

9

PL/SQL Code for retrieving Student Records

INTO :student_edit.student_name, :student_edit.email, :student_edit.year

Into a list of Location of the Textboxes accordingly 

FROM student 

From Student Table in the database

10

ISOM3260 Lab (Stage 1) 96

Page 97: database design intro(database)

PL/SQL Code for retrieving Student Records

WHERE student_id=:student_edit.student_id;

Set the criteria to display the record, of which the student ID equals what user inserts in the textbox

: STUDENT_EDIT. STUDENT_ID

11

Test the program• Retrieve a student by typing a student ID

• Can you change the name, email and year of the student retrieved? 

The field is protected and therefore no one can change the value ofthe 3 textboxes

12

ISOM3260 Lab (Stage 1) 97

Page 98: database design intro(database)

Test the program

• How?

– Right click the textbox

– Set Update allowed and Insert allowed to “NO” to avoid user changing the values retrieved under Property Palette 

13

Standardized Exception (1)

• Oracle Forms generates standardized exceptions to protect data integrity:

• Example:– Primary Key clash (ORA‐00001)

– NULL value in mandatory key fields (ORA‐01400)

– Value exceed the column size (ORA‐01401) 

– No query result retrieved (ORA‐01403)

– Wrong datatype (ORA‐06502)

(Insert string into numeric fields)

– Some others….

14

ISOM3260 Lab (Stage 1) 98

Page 99: database design intro(database)

Standardized Exception (2)

Users are not supposed deal with the error codes when using aninformation system. This is considered as an unhandled exception – a system bug

15

Standardized Exception (3)

• How to check the exception code?

– Type in the code and Google it …

16

ISOM3260 Lab (Stage 1) 99

Page 100: database design intro(database)

Class Practice

• Create a page for users to update student information

Datablock: STUDENT_UPDATECanvas: STUDENT_UPDATE_C

17

VERY IMPORTANT!

• Check the objects you just created belong to the dummy datablock(drag the object back to the right place)

• Move the datablocks so that the datablock of the LOGIN page goes first

ISOM3260 Lab (Stage 1) 100

Page 101: database design intro(database)

Why do we need validation triggers?

There are some instancesEntered by users that are not valid!!!!

19

Validation Triggers in Forms Developer

• Validation triggers ensure users insert correct values in the system

• Example: 

– Student_ID should be in 8‐characters

– Year should not exceed 5 and should not less than 0

20

ISOM3260 Lab (Stage 1) 101

Page 102: database design intro(database)

Review the codes of Validation Triggers 

21

Summary

• Examine the PL/SQL code to retrieve Student records

• Understand 5 common error codes in Oracle

• Apply PL/SQL code to retrieve and update Student records

• Understand the need of validation triggers

• Apply different kinds of validation triggers for project

22

ISOM3260 Lab (Stage 1) 102

Page 103: database design intro(database)

Progress Demonstration 1 (7%)

• Deliverable1. Entity‐relationship Diagram

2. Data Dictionary

3. Workable system with the following functions:• Allow staff to insert new product information

• Allow staff to update product information

• Allow customers to register as members 

(i.e., insert new member information)

• Allow customers to update customer information

• Login as members and staff

23

Progress Demonstration 1 (7%)

• Refer to Progress Demonstration 1 checklist for the grading criteria

24

ISOM3260 Lab (Stage 1) 103

Page 104: database design intro(database)

Reminder: Merging modules into 1

• You should merge all the group work, and submit only 1 fmb file for the demonstration/final project presentation

• By simple drag and drop 

• Drag all Datablocks, Canvases (and later, LOVs, Program Units, Reports, Alerts)

ISOM3260 Lab (Stage 1) 104

Page 105: database design intro(database)

 

 

End of Stage 1 

Page 106: database design intro(database)

Spring 2014

Page 1 of 11

ISOM3260 Database Design and Administration Project Guideline

Overview To truly learn how to build business applications with databases, you need to work on a group project. The group project is simpler than real life cases, but complex enough to illustrate common problems that you may encounter. The project will reinforce the concepts discussed in lectures, especially database design (ER diagrams, normalization, SQL). By working on the project throughout the semester, you can have a better understanding of the topics. Project Requirements This group project (6 members each) is to develop a database system for a newly established e-Commerce company. It contributes 30 points (30%) to the course grade. By the end of the project, students should be able to Non-technical

Perform a comprehensive analysis on functional requirements, both data and process Allocate different tasks to group members effectively as in IT development projects Build professional IT documentations

Technical

Perform data modeling of the application using Toad Data Modeler Build a simple information system using a database programming language - PL/SQL Compile valuable managerial reports from the database using SQL Work with contemporary Oracle products

Deliverables 1. Progress Demonstrations (15%) All project groups are required to demonstrate the progress of their project twice throughout the semester. It is mandatory for each group walk-through the project with the tutor during the two demonstrations. This is to make sure the project is developed on an appropriate track.

Date Duration Weighing Progress Demonstration I 13, 14 March 2014 20 mins 7% Progress Demonstration II 10, 11, 15 April 2014 25 mins 8%

There will be no make-up demonstrations available. Groups which are failed to demonstrate during the specified periods are scored 0% in the demonstrations.

ISOM3260 Lab (Stage 1) 105

Page 107: database design intro(database)

Spring 2014

Page 2 of 11

Progress Demonstration I : System Analysis and Design (7%) In the first Progress Demonstration, project groups should prepare a progress documentation which includes the following:

Data-related o Conceptual data model (i.e., ER Diagram) o Data Dictionary

Describes the attributes names, meanings, data types, sizes and attribute domains (if any) of each Entity.

Process-related o A list of functions to be implemented

In addition to the progress documentation, project groups should also show the table structure physically created in the Oracle Database. In addition, all project groups should demonstrate their ‘workable’ systems with the following functions:

a. Allow staff to insert new product information

b. Allow staff to update product information

d. Allow customers to register as members

e. Allow members to update their personal information

ISOM3260 Lab (Stage 1) 106

Page 108: database design intro(database)

Spring 2014

Page 3 of 11

Progress Demonstration II: System Implementation and Testing (8%) In the second Progress Demonstration, all project groups should demonstrate their ‘workable’ systems with the following functions:

c. Allow staff to prepare managerial reports (Note: Only prepare for a dummy page for managerial reports by the time of demonstration)

f. Allow members search products and view product details

g. Allow members to make purchase

h. Allow members to view their order records

Meanwhile, project groups are welcomed to demonstrate the extra functions implemented In addition, project groups are required to show a Problem Log. A Problem Log serves the following purposes:

Encourage project teams to carefully test the functions of the system before demonstration

Help project teams to systematically document system flaws and bugs that are found, and the person who is responsible for resolving the flaws and bugs

Help the instructor monitor the progress of each group and resolve conflicts All group members should take the responsibility of maintaining one Problem Log. You are recommended to import the Problem Log as a Spreadsheet into online collaboration platforms such as Google Drive. And be sure that every group member should have access to it. “Problem Log” is a document that is widely used in IT Project Management. It is important for group members to maintain problem log such that it serves the intended purposes, you should not build a Problem Log deliberately for grading purpose.

ISOM3260 Lab (Stage 1) 107

Page 109: database design intro(database)

Spring 2014

Page 4 of 11

Sample Problem Log (Extracts):

Problem ID

Date Created by

Module Error Description

Severity Actions to be taken

Responsible Person and Status

13 19/3 William Customer Unable to read multiple lines of Shopping Cart

Medium Infinite loop – Declare a separate variable for the second loop

Fixed by Chris Test OK on 22/3

14 30/3 Angie Customer No scroll bar for product description

Low Enable it in Forms Developer

Fixed by William Test OK on 1/4

15 31/3 Linda Staff Cannot update product information, records do not change accordingly in Database

High To be checked by Angie and William Problem not fixed

ISOM3260 Lab (Stage 1) 108

Page 110: database design intro(database)

Spring 2014

Page 5 of 11

2. Project Demonstration and Final Report (15%) All groups must conduct final project demonstrations to the professor and tutor on 7-9 May. Each group is given 30 minutes to demonstrate all functions and managerial reports of their systems. Details and rules will be given in due course. After the project demonstration, all project groups are required to submit a Final Report. The report is the formal document of your system. It should be integrate all work you have done in this semester, containing the following sections: 1. Introduction to the project – 1 page 2. Conceptual data model (improved from Progress Demonstration I) – 2 to 3 pages

You should present the finalized E-R diagram and provide necessary explanations of the model, such as why specific entity classes, relationships, and attributes are modeled in your model. You should state the business rules and assumptions you have made.

3. Logical data model – 1 to 2 pages, landscape

You should map the E-R diagram into relations and normalize the relations into 3NF. To prove that the relations are all in 3NF, you must list all functional dependencies for every relation. You may consider using Excel to draw the relations, with hand-drawn functional dependencies and referential integrity.

4. Data dictionary (improved from Progress Demonstration I) – 2 to 10 pages

You should describe all tables including their attributes, primary keys, and foreign keys.

5. Functional Requirements (improved from Progress Demonstration I) – 2 to 3 pages You should include a list of functions that you have implemented, including extra functions (if any), you may find Context Diagram and Use Case Diagram useful in this section.

6. A brief conclusion - 0.5 page

Summarize the state of your project and any thoughts you have on this project including suggestions and comments for further development. Above all, please highlight the important features of your project.

Appendix A. Problem Log

Document the system bugs you found while testing, including the error descriptions, actions taken person responsible and current status. You can leave the outstanding issues in the Problem Log, if any.

B. Assumptions

You should document any extra assumptions (in point form) that you make when you implement the project.

ISOM3260 Lab (Stage 1) 109

Page 111: database design intro(database)

Spring 2014

Page 6 of 11

Note: The length of the report (excluding Appendix) should not exceed 30 pages.

As your project is graded based on the final report, it is very important to follow the

guideline above to prepare and organize your final report. Omission of any part of the report will result in deduction of the project grade.

You should make sure that the final report is consistent with what you actually

implemented. Consistency is part of the project score.

You do not have to make any screenshots of your project, and you do not have to copy any codes written onto your final report

Peer Evaluation Each member is required to submit a peer evaluation form to evaluate the contribution of all members after the project submission. You are recommended to reflect the actual contribution of every group member with honesty. For students who do not contribute in the project and take the advantage of others’ contribution (i.e., Free-riders), their project scores are adjusted, and may result to a fail grade in the course.

Important Dates Progress Demonstration I 13, 14 March 2014

Progress Demonstration II 10, 11, 15 April 2014 Final Report

7, 8 ,9 May 2014

Project Presentation 7, 8, 9 May 2014

ISOM3260 Lab (Stage 1) 110

Page 112: database design intro(database)

Spring 2014

Page 7 of 11

Project Case 1. Introduction

Recently founded by a group of HKUST business graduates, Softwareman is an e-Commerce company selling off-the-shelf PC software package CD/DVD, etc. Your team has been hired as IT consultants to develop an online purchasing system for the company.

2. Requirements Definition

Softwareman has a similar business model as typical online retailing stores of other products like Amazon for books, YesAsia for CDs, etc. For simplicity, customers are required to register as members, before they can log in to the system.

Customers view available products in the system directly. Search functions should be implemented such that customers can search for their desired products using keywords.

When customer find favorite products, he inserts products into shopping cart. The products in his shopping cart should be stored such that the products can be retrieved next time when he logs into the system.

Customer views the shopping cart and makes changes. For instance, changing purchase quantity of different products, remove undesired products, etc. Customer proceeds with purchase through shopping cart page when he is ready. He inputs a credit card number to make purchase. After payment is confirmed, order is stored in the database. Moreover, customer can view his purchasing record using the system.

On the other hand, staff log into the system to manage products. For instance, adding new products, changing the inventory of products, modifying price of products, etc.

Manager, who is also the staff of the company, can also login to the system and generate managerial reports for making decisions on product portfolio, replenishment strategies, etc.

ISOM3260 Lab (Stage 1) 111

Page 113: database design intro(database)

Spring 2014

Page 8 of 11

3. Use case diagram of the system

ISOM3260 Lab (Stage 1) 112

Page 114: database design intro(database)

Spring 2014

Page 9 of 11

4. Summarized Basic functional requirements

Data Requirement a. Member data (e.g., name, address, email, password, status, etc.)

b. Product data (e.g., brand, name, price, inventory, description, category, etc.)

c. Order data (e.g., member id, date, order total, etc.)

d. Order line data (e.g., products sold in each order, quantity, subtotal, etc.)

e. Shopping cart line data (e.g., member id, product id, quantity, etc.)

f. Staff login data (e.g., ID, password, etc.)

g. Any other data that you think will be relevant to additional functions Process Requirement

Staff a. Allow staff to insert new product information

b. Allow staff to update product information

c. Allow staff to prepare managerial reports (refer below for the managerial reports requirement)

Customer/Member

d. Allow customers to register as members

e. Allow members to update their personal information

f. Allow members to search products and view product details

g. Allow members to make purchase

h. Allow members to view their order records

Managerial Reports Requirements a. Report total sales of a selected date

b. Report total sales of last 30 days

(Note: Show the breakdown of the sales calculation by each sales order)

c. Report on the 10 most popular products, in terms of quantity sold

d. Report on the top 10 customers, in terms of sales value

e. Report sales of a particular product, in terms of quantity sold

f. Report sales of a particular category, in terms of quantity sold

g. Report showing stock-out products

ISOM3260 Lab (Stage 1) 113

Page 115: database design intro(database)

Spring 2014

Page 10 of 11

5. Assumptions a) You can assume the verification of validity of credit card is done by the Credit Card

Clearing House. You do not have to verify whether the credit card number, CVC number and expiry date inserted by the customers are correct.

b) Assume the system only sells off-the-shelf software packages, not

customization/installation services. c) This is a purchasing system. You can assume that other business functions, such as

Accounting, Logistics, etc. are not handled by this system. d) In this phase, we decided to store the information of all products in English only.

e) For simplicity, you can use ERD, but not Enhanced ERD, for the system design.

f) For simplicity, you are not required to use images, videos, sound clips in this system.

ISOM3260 Lab (Stage 1) 114

Page 116: database design intro(database)

Spring 2014

Page 11 of 11

6. Extra functional requirements (Optional) Due to time constraints, Softwareman has 3 sets of extra functional requirements which cannot be included in the basic functional requirements above. Your team may consider implementing 1 of the 3 sets for Softwareman: Set 1 a) Update order status - Allow staff to update order status for orders such that customers know whether the orders are still under preparation, or on delivery, when they view the order records. b) ‘Forget password’ - Allow customers to retrieve the login password/reset the login password in case they have forgotten. Set 2 a) Apply discount - Allow customers to enjoy discounts when purchasing products. Set 3 a) Rate and comment products Allow customer to rate and comment products. Average rating and all comments are displayed to other customers. b) Display “hot products” on the main page Allow the customer to view hot products on the main page. (Note: Your team can define “hot products” on your own. For instance, a product maybe defined as hot in terms of sales quantity)

ISOM3260 Lab (Stage 1) 115