Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Practical Database Programming With Java

.pdf
Скачиваний:
778
Добавлен:
10.06.2015
Размер:
31.58 Mб
Скачать

6 Chapter 1 Introduction

INSTRUCTOR AND CUSTOMER SUPPORT

The teaching materials for all chapters have been extracted and represented by a sequence of Microsoft Power Point files, one file for each chapter. Interested instructors can find those teaching materials in the folder TeachingPPT that is located at the site http:// www.wiley.com, and those instructor materials are available on request from the book’s listing on http://www.wiley.com (see Fig. 1.2).

Instructor materials are available upon request from the book’s listing on www.wiley.com

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DBProjects

 

 

 

 

TeachingPPT

 

JSP Files

 

Images

 

HWSolutions

 

 

Database

 

Appendix

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix A

 

 

 

 

 

 

 

 

 

Chapter 1.ppt

 

 

 

 

 

9-Faculty

HWSolution.pdf

 

Access

 

 

 

 

 

 

 

 

 

Chapter 5

 

 

 

 

 

Chapter 2.ppt

 

 

 

 

 

 

 

 

 

 

 

 

Appendix B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

14 Projects

 

 

 

 

Images

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Chapter 3.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

CSE_DEPT.accdb

Appendix C

 

Chapter 6

 

 

 

 

 

All JSP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4 Projects

Chapter 4.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

SQLServer

 

 

 

 

 

Appendix D

 

 

 

 

 

 

 

 

 

 

Files

 

 

5-Student

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix E

 

Chapter 7

 

 

 

 

 

Chapter 5.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Images

 

 

 

CSE_DEPT.mdf

 

 

 

 

 

 

 

 

4 Projects

Chapter 6.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Chapter 7.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Oracle

 

 

 

 

 

Appendix G

 

Chapter 8

 

6 Projects

 

 

 

 

1-Default

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Chapter 8.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

login.txt

 

 

 

 

Appendix H

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Image

 

 

 

 

 

 

 

 

 

 

 

 

 

Chapter 9

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Chapter 9.ppt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

faculty.txt

 

 

 

 

Appendix I

 

 

9 Projects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

course.txt

 

 

 

 

Appendix J

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

student.txt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix K

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

studentcourse.txt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ftp://ftp.wiley.com/public/sci_tech_med/practical_database_Java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Database

 

 

 

 

 

 

 

 

 

 

 

 

DBProjects

 

 

 

 

Images

 

JSP Files

 

 

 

 

Appendix

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix A

 

 

 

 

 

 

 

9-Faculty

 

 

 

 

Access

 

 

 

 

 

 

 

 

 

 

 

Chapter 5

 

 

 

 

 

 

 

 

 

 

Appendix B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

14 Projects

 

 

Images

 

 

 

 

 

CSE_DEPT.accdb

Appendix C

 

Chapter 6

 

 

 

 

 

 

All JSP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4 Projects

 

 

 

 

Files

 

 

 

 

 

 

 

 

 

 

 

Appendix D

 

 

 

 

SQLServer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix E

 

 

Chapter 7

 

 

 

5-Student

 

 

 

CSE_DEPT.mdf

 

 

4 Projects

 

 

Images

 

 

 

 

 

 

 

 

 

 

 

Appendix F

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Oracle

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix G

 

Chapter 8

 

6 Projects

 

1-Default

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

login.txt

 

 

 

 

 

Appendix H

 

 

 

 

 

 

 

 

 

Image

 

 

 

faculty.txt

 

 

 

 

 

 

Appendix I

 

 

Chapter 9

 

9 Projects

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

course.txt

 

 

 

 

 

 

Appendix J

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

student.txt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Appendix K

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

studentcourse.txt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 1.2. Book related materials on the Web sites.

Homework Solutions 7

E-mail support is available to readers of this book. When you send email to us, please provide the following information:

A detailed description about your problem, including the error message and debug message, as well as the error or debug number, if it is provided.

Your name, job title, and company name.

Please send all questions to the email address: baidbbook@bellsouth.net.

HOMEWORK SOLUTIONS

A selected homework solution is available on request from the book’s listing on http:// www.wiley.com.

Chapter 2

Introduction to Databases

SATISH BHALLA AND YING BAI

Databases have become an integral part of our modern-day life. We are an informationdriven society. We generate large amounts of data that is analyzed and converted into information. A recent example of biological data generation is the Human Genome Project, which was jointly sponsored by the Department of Energy and the National Institute of Health. Many countries in the world participated in this venture for 10 years. The project was a tremendous success. It was completed in 2003 and resulted in the generation of a huge amount of genome data, currently stored in databases around the world. The scientists will be analyzing this data in years to come.

Database technology has a direct impact on our daily lives. Decisions are routinely made by organizations based on the information collected and stored in the databases. A record company may decide to market certain albums in selected regions based on the music preference of teenagers. Grocery stores display more popular items at the eye level, and reorders are based on the inventories taken at regular intervals. Other examples include book orders by the libraries, club memberships, auto part orders, winter cloth stock by department stores, and many others.

Database management programs have been in existence since the 1960s. However, it was not until the seventies when E. F. Codd proposed the then revolutionary relational data model that database technology really took off. In the early eighties, it received a further boost with the arrival of personal computers and microcomputer-based data management programs like dBase II (later followed by dBase III and IV). Today we have a plethora of vastly improved programs for PCs and mainframe computers, including Microsoft Access, IBM DB2, Oracle, Sequel Server, My SQL, and others.

This chapter covers the basic concepts of database design followed by implementation of a specific relational database to illustrate the concepts discussed here. The sample database, CSE_DEPT, is used as a running example. The database creation is shown in detail using Microsoft Access, SQL Server, and Oracle.The topics discussed in this chapter include:

Practical Database Programming with Java, First Edition. Ying Bai.

© 2011 the Institute of Electrical and Electronics Engineers, Inc. Published 2011 by John Wiley & Sons, Inc.

9

10Chapter 2 Introduction to Databases

What are databases and database programs?

File processing system

Integrated databases

Various approaches to developing a database

Relational data model and entity-relationship model (ER)

Identifying keys

Primary keys, foreign keys and referential integrity

Defining relationships

Normalizing the data

Implementing the relational database

Create a Microsoft Access sample database

Create a Microsoft SQL Server 2008 sample database

Create an Oracle sample database

2.1 WHAT ARE DATABASES AND DATABASE PROGRAMS?

A modern-day database is a structured collection of data stored in a computer. The term structured implies that each record in the database is stored in a certain format. For example, all entries in a phone book are arranged in a similar fashion. Each entry contains a name, an address, and a telephone number of a subscriber. This information can be queried and manipulated by database programs. The data retrieved in answer to queries become information that can be used to make decisions. The databases may consist of a single table or related multiple tables. The computer programs used to create, manage, and query databases are known as database management systems (DBMS). Just like the databases, the DBMS vary in complexity. Depending on the need of a user, one can use either a simple application or a robust program. Some examples of these programs were given earlier.

2.1.1 File Processing System

The file processing system is a precursor of the integrated database approach. The records for a particular application are stored in a file. An application program is needed to retrieve or manipulate data in this file. Thus, various departments in an organization will have their own file processing systems with their individual programs to store and retrieve data. The data in various files may be duplicated and not available to other applications. This causes redundancy and may lead to inconsistency, meaning that various files that supposedly contain the same information may actually contain different data values.Thus, duplication of data creates problems with data integrity. Moreover, it is difficult to provide access to multiple users with the file processing systems without granting them access to the respective application programs, which manipulate the data in those files.

The file processing system may be advantageous under certain circumstances. For example, if data is static and a simple application will solve the problem, a more expensive DBMS is not needed. For example, in a small business environment, you want to keep

2.1 What Are Databases and Database Programs? 11

track of the inventory of the office equipment purchased only once or twice a year. The data can be kept in an Excel spreadsheet and manipulated with ease from time to time. This avoids the need to purchase an expensive database program and hiring a knowledgeable database administrator. Before the DBMS became popular, the data was kept in files, and application programs were developed to delete, insert, or modify records in the files. Since specific application programs were developed for specific data, these programs lasted for months or years before modifications were necessitated by business needs.

2.1.2 Integrated Databases

A better alternative to a file processing system is an integrated database approach. In this environment, all data belonging to an organization is stored in a single database. The database is not a mere collection of files; there is a relation between the files. Integration implies a logical relationship, usually provided through a common column in the tables. The relationships are also stored within the database. A set of sophisticated programs known as DBMS is used to store, access and manipulate the data in the database. Details of data storage and maintenance are hidden from the user. The user interacts with the database through the DBMS. A user may interact either directly with the DBMS or via a program written in a programming language, such as C++, Java, or Visual Basic. Only the DBMS can access the database. Large organizations employ Database Administrators (DBAs) to design and maintain large databases.

There are many advantages to using an integrated database approach over that of a file processing approach:

1.Data Sharing: The data in the database is available to a large numbers of users who can access the data simultaneously and create reports and manipulate the data given proper authorization and rights.

2.Minimizing Data Redundancy: Since all the related data exists in a single database, there is a minimal need of data duplication. The duplication is needed to maintain relationship between various data items.

3.Data Consistency and Data Integrity: Reducing data redundancy will lead to data consistency. Since data is stored in a single database, enforcing data integrity becomes much easier. Further more, the inherent functions of the DBMS can be used to enforce the integrity with minimum programming.

4.Enforcing Standards: DBAs are charged with enforcing standards in an organization. DBA takes into account the needs of various departments and balances it against the overall need of the organization. DBA defines various rules, such as documentation standards, naming conventions, update and recovery procedures, and so on. It is relatively easy to enforce these rules in a Database System, since it is a single set of programs that is always interacting with the data files.

5.Improving Security: Security is achieved through various means, such as controlling access to the database through passwords, providing various levels of authorizations, data encryption, providing access to restricted views of the database, and so on.

6.Data Independence: Providing data independence is a major objective for any database system. Data independence implies that even if the physical structure of a database changes, the applications are allowed to access the database as before the changes were implemented.

12 Chapter 2 Introduction to Databases

In other words, the applications are immune to the changes in the physical representation and access techniques.

The downside of using an integrated database approach has mainly to do with exorbitant costs associated with it.The hardware, the software, and maintenance are expensive. Providing security, concurrency, integrity, and recovery may add further to this cost. Furthermore, since DBMS consists of a complex set of programs, trained personnel are needed to maintain it.

2.2 DEVELOP A DATABASE

Database development process may follow a classical Systems Development Life Cycle.

1.Problem Identification: Interview the user, identify user requirements. Perform preliminary analysis of user needs.

2.Project Planning: Identify alternative approaches to solving the problem. Does the project need a database? If so, define the problem. Establish scope of the project.

3.Problem Analysis: Identify specifications for the problem. Confirm the feasibility of the project. Specify detailed requirements.

4.Logical Design: Delineate detailed functional specifications. Determine screen designs, report layout designs, data models, and so on.

5.Physical Design: Develop physical data structures.

6.Implementation: Select DBMS. Convert data to conform to DBMS requirements. Code programs; perform testing.

7.Maintenance: Continue program modification until desired results are achieved.

An alternative approach to developing a database is through a phased process, which will include designing a conceptual model of the system that will imitate the real-world operation. It should be flexible and change when the information in the database changes. Furthermore, it should not be dependent upon the physical implementation. This process follows the following phases:

1.Planning and Analysis: This phase is roughly equivalent to the first three steps mentioned above in the Systems Development Life Cycle. This includes requirement specifications, evaluating alternatives, determining input, output, and reports to be generated.

2.Conceptual Design: Choose a data model and develop a conceptual schema based on the requirement specification that was laid out in the planning and analysis phase. This conceptual design focuses on how the data will be organized without having to worry about the specifics of the tables, keys, and attributes. Identify the entities that will represent tables in the database; identify attributes that will represent fields in a table; and identify each entity attribute relationship. Entity–relationship diagrams provide a good representation of the conceptual design.

3.Logical Design: Conceptual design is transformed into a logical design by creating a roadmap of how the database will look before actually creating the database. Data model is identified; usually it is the relational model. Define the tables (entities) and fields (attributes). Identify primary and foreign key for each table. Define relationships between the tables.

2.3 Sample Database 13

4.Physical Design: Develop physical data structures; specify file organization, and data storage and so on. Take into consideration the availability of various resources, including hardware and software. This phase overlaps with the implementation phase. It involves the programming of the database taking into account the limitations of the DBMS used.

5.Implementation: Choose the DBMS that will fulfill the user needs. Implement the physical design. Perform testing. Modify if necessary or until the database functions satisfactorily.

2.3 SAMPLE DATABASE

We will use CSE_DEPT database to illustrate some essential database concepts. Tables

2.1–2.5 show sample data tables stored in this database.

The data in CSE_DEPT database is stored in five tables—LogIn, Faculty, Course, Student, and StudentCourse. A table consists of row and columns (Fig. 2.1). A row represents a record and the column represents a field. A row is called a tuple and a column is called an attribute. For example, the Student table has seven columns or fields— student_id, name, gpa, major, schoolYear, and email. It has five records or rows.

Table 2.1. LogIn table

 

 

 

 

 

 

 

 

user_name

pass_word

faculty_id

student_id

 

abrown

america

B66750

 

 

ajade

tryagain

 

A97850

 

awoods

smart

 

A78835

 

banderson

birthday

A52990

 

 

bvalley

see

 

B92996

 

dangles

tomorrow

A77587

 

 

hsmith

try

 

H10210

 

 

 

jerica

excellent

 

J77896

 

jhenry

test

H99118

 

 

pjking

goodman

K69880

 

 

sbhalla

india

B86590

 

 

sjohnson

jermany

J33486

 

 

ybai

reback

B78880

 

 

Table 2.2.

Faculty table

 

 

 

 

 

 

 

 

 

 

 

faculty_id

faculty_name

office

phone

college

title

email

A52990

Black Anderson

MTC-218

750-378-9987

Virginia Tech

Professor

banderson@college.edu

A77587

Debby Angles

MTC-320

750-330-2276

University of Chicago

Associate Professor

dangles@college.edu

B66750

Alice Brown

MTC-257

750-330-6650

University of Florida

Assistant Professor

abrown@college.edu

B78880

Ying Bai

MTC-211

750-378-1148

Florida Atlantic University

Associate Professor

ybai@college.edu

B86590

Satish Bhalla

MTC-214

750-378-1061

University of Notre Dame

Associate Professor

sbhalla@college.edu

H99118

Jeff Henry

MTC-336

750-330-8650

Ohio State University

Associate Professor

jhenry@college.edu

J33486

Steve Johnson

MTC-118

750-330-1116

Harvard University

Distinguished Professor

sjohnson@college.edu

K69880

Jenney King

MTC-324

750-378-1230

East Florida University

Professor

jking@college.edu

14 Chapter 2 Introduction to Databases

 

 

 

 

Table 2.3.

Course table

 

 

 

 

 

 

 

 

 

 

 

 

 

 

course_id

course

credit

classroom

schedule

 

enrollment

faculty_id

CSC-131A

Computers in Society

3

TC-109

M-W-F: 9:00-9:55 AM

28

A52990

CSC-131B

Computers in Society

3

TC-114

M-W-F: 9:00-9:55 AM

 

20

B66750

CSC-131C

Computers in Society

3

TC-109

T-H: 11:00-12:25 PM

 

25

A52990

CSC-131D

Computers in Society

3

TC-109

M-W-F: 9:00-9:55 AM

 

30

B86590

CSC-131E

Computers in Society

3

TC-301

M-W-F: 1:00-1:55 PM

 

25

B66750

CSC-131I

Computers in Society

3

TC-109

T-H: 1:00-2:25 PM

 

32

A52990

CSC-132A

Introduction to Programming

3

TC-303

M-W-F: 9:00-9:55 AM

 

21

J33486

CSC-132B

Introduction to Programming

3

TC-302

T-H: 1:00-2:25 PM

 

21

B78880

CSC-230

Algorithms & Structures

3

TC-301

M-W-F: 1:00-1:55 PM

 

20

A77587

CSC-232A

Programming I

3

TC-305

T-H: 11:00-12:25 PM

 

28

B66750

CSC-232B

Programming I

3

TC-303

T-H: 11:00-12:25 PM

 

17

A77587

CSC-233A

Introduction to Algorithms

3

TC-302

M-W-F: 9:00-9:55 AM

 

18

H99118

CSC-233B

Introduction to Algorithms

3

TC-302

M-W-F: 11:00-11:55 AM

 

19

K69880

CSC-234A

Data Structure & Algorithms

3

TC-302

M-W-F: 9:00-9:55 AM

 

25

B78880

CSC-234B

Data Structure & Algorithms

3

TC-114

T-H: 11:00-12:25 PM

 

15

J33486

CSC-242

Programming II

3

TC-303

T-H: 1:00-2:25 PM

 

18

A52990

CSC-320

Object Oriented Programming

3

TC-301

T-H: 1:00-2:25 PM

 

22

B66750

CSC-331

Applications Programming

3

TC-109

T-H: 11:00-12:25 PM

 

28

H99118

CSC-333A

Computer Arch & Algorithms

3

TC-301

M-W-F: 10:00-10:55 AM

22

A77587

CSC-333B

Computer Arch & Algorithms

3

TC-302

T-H: 11:00-12:25 PM

 

15

A77587

CSC-335

Internet Programming

3

TC-303

M-W-F: 1:00-1:55PM

 

25

B66750

CSC-432

Discrete Algorithms

3

TC-206

T-H: 11:00-12:25 PM

 

25

B86590

CSC-439

Database Systems

3

TC-206

M-W-F: 1:00-1:55 PM

18

B86590

CSE-138A

Introduction to CSE

3

TC-301

T-H: 1:00-2:25 PM

 

15

A52990

CSE-138B

Introduction to CSE

3

TC-109

T-H: 1:00-2:25 PM

 

35

J33486

CSE-330

Digital Logic Circuits

3

TC-305

M-W-F: 9:00-9:55 AM

 

26

K69880

CSE-332

Foundations of Semiconductors

3

TC-305

T-H: 1:00-2:25 PM

 

24

K69880

CSE-334

Elec. Measurement & Design

3

TC-212

T-H: 11:00-12:25 PM

 

25

H99118

CSE-430

Bioinformatics in Computer

3

TC-206

Thu: 9:30-11:00 AM

 

16

B86590

CSE-432

Analog Circuits Design

3

TC-309

M-W-F: 2:00-2:55 PM

 

18

K69880

CSE-433

Digital Signal Processing

3

TC-206

T-H: 2:00-3:25 PM

 

18

H99118

CSE-434

Advanced Electronics Systems

3

TC-213

M-W-F: 1:00-1:55 PM

 

26

B78880

CSE-436

Automatic Control and Design

3

TC-305

M-W-F: 10:00-10:55 AM

 

29

J33486

CSE-437

Operating Systems

3

TC-303

T-H: 1:00-2:25 PM

 

17

A77587

CSE-438

Advd Logic & Microprocessor

3

TC-213

M-W-F: 11:00-11:55 AM

 

35

B78880

CSE-439

Special Topics in CSE

3

TC-206

M-W-F: 10:00-10:55 AM

 

22

J33486

Table 2.4.

Student table

 

 

 

 

 

 

 

 

 

 

 

student_id

student_name

gpa

credits

major

schoolYear

email

A78835

Andrew Woods

3.26

108

Computer Science

Senior

awoods@college.edu

A97850

Ashly Jade

3.57

116

Information System Engineering

Junior

ajade@college.edu

B92996

Blue Valley

3.52

102

Computer Science

Senior

bvalley@college.edu

H10210

Holes Smith

3.87

78

Computer Engineering

Sophomore

hsmith@college.edu

J77896

Erica Johnson

3.95

127

Computer Science

Senior

ejohnson@college.edu

 

 

 

 

 

 

 

2.3 Sample Database 15

Table 2.5. StudentCourse table

s_course_id

student_id

course_id

credit

major

1000

H10210

CSC-131D

3

CE

1001

B92996

CSC-132A

3

CS/IS

1002

J77896

CSC-335

3

CS/IS

1003

A78835

CSC-331

3

CE

1004

H10210

CSC-234B

3

CE

1005

J77896

CSC-234A

3

CS/IS

1006

B92996

CSC-233A

3

CS/IS

1007

A78835

CSC-132A

3

CE

1008

A78835

CSE-432

3

CE

1009

A78835

CSE-434

3

CE

1010

J77896

CSC-439

3

CS/IS

1011

H10210

CSC-132A

3

CE

1012

H10210

CSC-331

2

CE

1013

A78835

CSC-335

3

CE

1014

A78835

CSE-438

3

CE

1015

J77896

CSC-432

3

CS/IS

1016

A97850

CSC-132B

3

ISE

1017

A97850

CSC-234A

3

ISE

1018

A97850

CSC-331

3

ISE

1019

A97850

CSC-335

3

ISE

1020

J77896

CSE-439

3

CS/IS

1021

B92996

CSC-230

3

CS/IS

1022

A78835

CSE-332

3

CE

1023

B92996

CSE-430

3

CE

1024

J77896

CSC-333A

3

CS/IS

1025

H10210

CSE-433

3

CE

1026

H10210

CSE-334

3

CE

1027

B92996

CSC-131C

3

CS/IS

1028

B92996

CSC-439

3

CS/IS

2.3.1 Relational Data Model

A data model is like a blue print for developing a database. It describes the structure of the database and various data relationships and constraints on the data. This information is used in building tables, keys, and defining relationships. Relational model implies that a user perceives the database as made up of relations, a database jargon for tables. It is imperative that all data elements in the tables are represented correctly. In order to achieve these goals, designers use various tools. The most commonly used tool is entity– relationship model (ER). A well-planned model will give consistent results and will allow changes if needed later on. The following section further elaborates on the ER Model.

16 Chapter 2 Introduction to Databases

Table

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ID

Name

Ages

Address

Phone

 

 

 

 

 

 

 

1000

Tom

36

220 Ave

549-0507

 

Record

 

 

 

 

1002

Jim

58

101 Main

678-1002

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2010

Jeff

49

25 Court

678-3211

 

 

 

 

 

 

 

 

 

 

3090

Kim

23

43 Route

202-5587

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Field

Figure 2.1. Records and fields in a table.

2.3.2 Entity–Relationship Model

The ER model was first proposed and developed by Peter Chen in 1976. Since then, Charles Bachman and James Martin have added some refinements; the model was designed to communicate the database design in the form of a conceptual schema. The ER model is based on the perception that the real world is made up of entities, their attributes, and relationships. The ER model is graphically depicted as entity–relationship diagrams (ERD). The ERD are a major modeling tool; they graphically describe the logical structure of the database. ERD can be used with ease to construct the relational tables, and are a good vehicle for communicating the database design to the end user or a developer. The three major components of ERD are entities, relationships, and the attributes.

Entities: An entity is a data object, either real or abstract, about which we want to collect information. For example, we may want to collect information about a person, a place, or a thing. An entity in an ER diagram translates into a table. It should preferably be referred to as an entity set. Some common examples are departments, courses, and students. A single occurrence of an entity is an instance. There are four entities in the CSE_Dept database, LogIn, Faculty, Course, and Student. Each entity is translated into a table with the same name. An instance of the Faculty entity will be Alice Brown and her attributes.

Relationships: A database is made up of related entities.There is a natural association between the entities; it is referred to as relationship. For example,

Students take courses

Departments offer certain courses

Employees are assigned to departments

The number of occurrences of one entity associated with single occurrence of a related entity is referred to as cardinality.

Attributes: Each entity has properties or values called attributes associated with it. The attributes of an entity map into fields in a table. Database processing is one attribute of an entity called Courses. The domain of an attribute is a set of all possible values from which an attribute can derive its value.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]