Beruflich Dokumente
Kultur Dokumente
ITS Training Services 23 Willard Building University Park, PA 16802 814-863-9522 itstraining@psu.edu http://its.psu.edu/training/ Version 02/22/2010
Statement of Non-Discrimination
The Pennsylvania State University is committed to the policy that all persons shall have equal access to programs, facilities, admission, and employment without regard to personal characteristics not related to ability, performance, or qualifications as determined by University policy or by state or federal authorities. It is the policy of the University to maintain an academic and work environment free of discrimination, including harassment. The Pennsylvania State University prohibits discrimination and harassment against any person because of age, ancestry, color, disability or handicap, national origin, race, religious creed, sex, sexual orientation, or veteran status. Discrimination or harassment against faculty, staff, or students will not be tolerated at The Pennsylvania State University. Direct all inquiries regarding the nondiscrimination policy to the Affirmative Action Director, The Pennsylvania State University, 328 Boucke Building, University Park, PA 16802-5901; Tel 814-865-4700/V, 814-863-1150/TTY.
Table of Contents
Objectives ........................................................................................................2 Database Definition and Terminology ..............................................................3 Relational Database Definition.........................................................................4 Database Management Systems .....................................................................5 Steps for Database Design ..............................................................................5 1) Formulate a Solution .........................................................................5 2) Gather Information ............................................................................6 3) Develop Fields ..................................................................................6 4) Organize Tables................................................................................7 5) Define Table Relationships ............................................................. 10 6) Test and Improve ............................................................................ 12 7) Develop Queries, Forms, and Reports............................................ 12 Signs of Good Database Design .................................................................... 13 Multi-User Considerations.............................................................................. 13 Resources...................................................................................................... 14
Objectives
Define basic database terminology Describe a database management system (DBMS) Consider possible database use Describe basic database normalization Recognize the types of table relationships Explain the steps involved in relational database design
Large
SQL Server Oracle DB2
Propose a solution: Describe what can be done to make this data easier to utilize. Should anything else be a focus here? _________________________________________________________________ _________________________________________________________________ _________________________________________________________________
2) Gather information and clarify needs. Talk to people currently involved with the data and anyone else who may have the potential to be a user of the application. *WHY: Users will know what they need/want to be able to do. Knowing requirements ahead of time will help ensure that the database design meets the needs of users. Ask questions such as: What information is available? Is it adequate to meet needs? How is the available information being used? Who maintains current data? Sketch out formatting of possible forms and/or reports (mailing labels, rosters, course offerings list, etc.) to make sure they are useful to users List some people to speak to and possible points to clarify: ______________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________
3) Develop a list of all useful fields. List all of the possible attributes that will be available within the database Break down information into the smallest meaningful units possible (Ex. use First Name and Last Name fields instead just one Name field) Eliminate redundancy (Ex. dont need both age and birth date) *REMINDER: Redundancy may be necessary in certain (yet infrequent) cases. For instance, if a course title changes it does not mean that all records with the previous title and the same course number need to be changed to eliminate redundancy. Determine if all proposed fields will be needed (used to calculate, show up on a report later), but also be as thorough as possible in field creation *NOTE: It is easier to create a field now and remove it if it is unused later than it is to create an additional field in an already existing and utilized table.
Designing a Relational Database: Overview 6
List fields: Create a list of possible fields needed in the database. No grouping is necessary at this point. _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________
4) Organize the fields into logical tables. Divide fields into categories or subjects. Each of these categories will represent a table. *NOTE: Be sure that each table has only one focus. If fields do not directly belong with that focus, consider moving them to a different table. (Ex. The Courses table is not necessarily the best place to keep detailed faculty information.) Assign key fields. A key field or primary key is a unique identifier for a record/entity (Ex. ID numbers, Course codes). These identifiers help to associate tables. They are not necessary, but highly recommended. *HINT: A primary key can also be made of multiple fields if needed. Example of a table with primary key field: In this case, StudentID is the primary key field. This means that each student record in the database has a unique identifier that both sets it apart and may help it to relate to records in other tables.
Students Table StudentID FirstName LastName Address City State PhoneNumber
Consider normalization rules. Normalization Rules: There are 5+ normalization rules (5 Normal Forms and Boyce-Codd), but most day-to-day database creation focuses on the first three. These rules are used to help create flexible, adaptable tables that have no redundancy and are easy to query. In other words, they ensure that there is a place for everything and everything in its place. 1) First Normal Form: -Each field contains the smallest meaningful data value possible (no fields with multiple values listed). Ex. First Name and Last Name as separate fields -There are NO repeating groups of fields. Ex. One field called Month instead of 12 fields called Jan, Feb, etc. 2) Second Normal Form -Each non-key field in the table must relate to the entire Primary Key value. Ex. In this table, StudentID & CourseID make up the Compound Primary Key This table does not satisfy the Second Normal Form because not all fields are related directly to entire the primary key. StudentID 12345 12345 CourseID 310.001 360.007 FirstName Mary Mary Grade A B
The table now satisfies the Second Normal Form because al fields relate directly to entire the primary key. StudentID 12345 12345 CourseID 310.001 360.007 Grade A B
3) Third Normal Form -Each non-key field in the table must relate directly to the single-field Primary Key value. Ex. In this table, Course ID is the single-field Primary Key This table does not satisfy the Third Normal Form because not all fields are related directly to the primary key. CourseID 310.001 110.003 Section 1 1 FacultyID 001 001 FacultyOffice 356 Smith 356 Smith
The table now satisfies the Third Normal Form because all fields relate directly to the primary key. CourseID 310.001 110.003 Section 1 1 FacultyID 001 001
Organize fields into tables: Create table names and list fields for each table.
*Reminder: Before moving to step 5, it is a good idea to check back on the information previously gathered to ensure that all requirements are included in the tables.
5) Determine and define table relationships. Identify fields that match among tables Decide how data is related based on these matching fields (Ex. Student table is a primary table with related records in Course Enrollment table, which is called the related table) Define relationships between the primary key of one table and the related or foreign key of another. These matching fields can have the exact same name or slightly different names, yet hold the same data.
Students Table StudentID FirstName LastName Address City State PhoneNumber Course Enrollment Table CourseID Student ID Grade Semester Year foreign key field
Add new fields and/or tables as needed to clarify relationships. Consider how relationships may be used to make queries and reports more efficient. Focus on the three types of table relationships. Three Types of Table Relationships: There are three types of table relationships. Each has its own unique purpose in helping to organize the data within the database. These relationships can be used to determine joins in queries as well. 1) One-to-One Relationships: one record in a table is related to one record in a related table; creates equally dependent tables Ex. one student has only one PSU ID *NOTE: This type of relationship is rarely used.
10
2) One-to-Many Relationships: one record in a primary table is related to many records in a related table; however, a record in the related table has only one related record in the primary table Ex. a student can live in one residence hall at a given time, but many students can live in a residence hall at a given time *NOTE: This is the most common type of relationship. 3) Many-to-Many Relationships: several records in the primary table are related to several records in a related table Ex. one student can be enrolled in many courses and each course can have many students enrolled Define relationships among tables: Draw lines to connect primary and foreign key fields on related tables.This diagramming is referred to as Entity Relationship diagramming because it connects entities based on similarities.
11
6) Test, refine and improve. Analyze the overall database design to check for errors as well as to see that needs are being met. Review table structure to make sure all needed fields are present and existing relationships are valid and useful. Test table design by adding records and observing functionality. List points to consider when testing, refining, and improving design: Describe possible issues and resolutions. _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________
7) Develop queries, forms, and reports. Look back at information gathered to get ideas for what type of queries, forms, and reports are needed. Consider table relationships and how they can be utilized. Try drafts of queries, forms, and reports to see if they show the expected data results. Modify as needed to meet needs. Consider this development process as on going throughout the use of the database. Describe possible queries, forms, and reports that may be needed: _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ _________________________________________________________________
12
Reference Books
Relational Database Design Clearly Explained, Second Edition by Jan L. Harrington Database Design Using Entity-Relationship Diagrams by Sikha Bagui and Richard Earp Handbook of Relational Database Design by Candace C. Fleming and Barbara von Halle Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design by Michael J. Hernandez Information Modeling and Relational Databases: From Conceptual Analysis to Logical Design by Terry Halpin
Websites
http://db.ittoolbox.com/ http://databases.about.com/
13
Technology Training Provided by ITS Training Services 23 Willard Building University Park, PA 16802 Phone: (814) 863-9522 Fax: (814) 865-3556 itstraining@psu.edu
http://its.psu.edu/training/