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

Practical Database Programming With Java

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

2.11 Create Oracle 10g XE Sample Database 67

To assign a primary key to our new LogIn table, select the Not Populated from the Primary Key selection list because we don’t want to use any Sequence object to assign any sequence to our primary key. The Sequence object in Oracle is used to automatically create a sequence of numeric number for the primary key. In our case, our primary key is a string, and therefore we cannot use this object. Keep the Primary Key Name, LOGIN_ PK , unchanged, and select the USER_NAME(VARCHAR2) from the Primary Key box. In this way, we select the user_name as the primary key for this table. Since we do not have any Composite Primary Key for this table, just keep this box unchanged. Your finished second step should match one that is shown in Figure 2.45. Click the Next button to continue to the next page—Set the foreign key page.

Since we have not created any other table, therefore, we cannot select our foreign key for this LogIn table right now. We leave this job to be handled later. Click the Next button to go to the next page. The next page allows you to set up some constraints on this table, which is shown in Figure 2.46.

No constraint is needed for this sample database at this moment, so you can click the Finish button to go to the last page to confirm our LogIn table. The opened Confirm page is shown in Figure 2.47.

Click the Create button to create and confirm this new LogIn table. Your created LogIn table should match one that is shown in Figure 2.48 if it is successful. The new created LogIn table is also added into the left pane.

After the LogIn table is created, the necessary editing tools are attached with this table and displayed at the top of this table. The top row of these tools contains object

Figure 2.46. The fourth step—setup constraints.

68 Chapter 2 Introduction to Databases

Figure 2.47. The last step—confirmation.

Figure 2.48. The created LogIn table.

2.11 Create Oracle 10g XE Sample Database 69

Figure 2.49. The opened Data page.

editing tools, and the bottom line includes the actual editing methods.The editing methods include Add Column, Modify Column, Rename Column, and Drop Column, and these methods are straightforward in meaning without question.

To add data into this new LogIn table, you need to use and open the Data object tool in the top row. Click the Data tool to open the Data page, which is shown in Figure 2.49.

Click the Insert Row button to open the data sheet view of the LogIn table, which is shown in Figure 2.50.

Add the following data into the first row:User Name—abrown, PassWord—America, Faculty Id—B66750. Since this user is a faculty, leave the Student Id column blank (don’t place a NULL in here, otherwise you will have trouble when you create a foreign key for this table later!). Your finished first row is shown in Figure 2.50.

Click the Create and Create Another button to create the next row. In the similar way, add each row that is shown in Table 2.23 into each row on the LogIn table.

You can click the Create button after you add the final row into your table. Your finished LogIn table should match one that is shown in Figure 2.51.

Next, let’s create our second table—Faculty table.

2.11.2.2 Create the Faculty Table

Click the Table tool on the top raw and click the Create button to create another new table. Select the Table item to open a new table page. Enter Faculty into the Table Name box as the name for this new table, and enter the following columns into this new table:

70 Chapter 2 Introduction to Databases

Figure 2.50. The opened data sheet view of the LogIn table.

Table 2.23. The data in the 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

 

jking

goodman

K69880

 

sbhalla

india

B86590

 

sjohnson

jermany

J33486

 

ybai

reback

B78880

 

faculty_id—VARCHAR2(10)

faculty_name—VARCHAR2 (20)

office—VARCHAR2 (10)

phone—CHAR(12)

college—VARCHAR2 (50)

Primary Key
FACULTY_ID(VARCHAR2)

2.11 Create Oracle 10g XE Sample Database 71

Figure 2.51. The completed LogIn table.

title—VARCHAR2 (30)

email—VARCHAR2 (30)

The popular data types used in the Oracle database include NUMBER, CHAR, and VARCHAR2. Each data type has its upper bound and low bound.The difference between the CHAR and the VARCHAR2 is that the former is used to store a fixed-length string, and the latter can provide a varying-length string, which means that the real length of the string depends on the number of real letters entered by the user. The data types for all columns are VARCHAR2 with one exception, which is the phone column that has a CHAR type with an upper bound of 12 letters, since our phone number is composed of 10 digits, and we can extend this length to 12 with two dashes. For all other columns, the length varies with the different information, so the VARCHAR2 is selected for those columns.

The finished design view of your Faculty table is shown in Figure 2.52. You need to check the Not Null checkbox for the faculty_id column, since we selected this column as the primary key for this table.

Click the Next button to go to the next page to add the primary key for this table, which is shown in Figure 2.53.

Check the Not Populated from the Primary Key list since we don’t want to use any Sequence object to automatically generate a sequence of numeric number as our primary key, and then select the from the

Figure 2.52. The finished design view of the Faculty table.

Figure 2.53. The opened Primary Key window.

72

2.11 Create Oracle 10g XE Sample Database 73

textbox. In this way, the faculty_id column is selected as the primary key for this table. Keep the Composite Primary Key box untouched, since we do not have that kind of key in this table, and click the Next button to go to the next page.

Since we have not created all other tables to work as our reference tables for the foreign key, click the Next to continue and we will do the foreign key for this table later. Click the Finish button to go to the Confirm page. Finally, click the Create button to create this new Faculty table. Your completed columns in the Faculty table are shown in Figure 2.54.

Now click the Data object tool to add the data into this new table. Click the Insert Row button to add all rows that are shown in Table 2.24 into this table.

Click the Create and Create Another button when the first row is done, and continue to create all rows with the data shown in Table 2.24. You may click the Create

Figure 2.54. The completed columns in the Faculty table.

Table 2.24. The data in the 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

74 Chapter 2 Introduction to Databases

Figure 2.55. The finished Faculty table.

button for your last row. Your finished Faculty table should match one that is shown in Figure 2.55.

2.11.2.3 Create Other Tables

In the similar way, you can continue to create the following three tables: Course, Student, and StudentCourse based on the data shown in Tables 2.25–2.27.

The data types used in the Course table are:

course_id: VARCHAR2(10)—Primary Key

course: VARCHAR2(40)

credit: NUMBER(1, 0)—precision = 1, scale = 0 (1-bit integer)

classroom: CHAR(6)

schedule: VARCHAR2(40)

enrollment: NUMBER(2, 0)—precision = 2, scale = 0 (2-bit integer)

faculty_id VARCHAR2(10)

The data types used in the Student table are:

student_id: VARCHAR2(10)—Primary Key

student_name: VARCHAR2(20)

gpa: NUMBER(3, 2)—precision = 3, scale = 2 (3-bit floating point data with 2-bit after the decimal point)

credits: NUMBER(3, 0)—precision = 3, scale = 0 (3-bit integer)

major: VARCHAR2(40)

2.11 Create Oracle 10g XE Sample Database 75

Table 2.25. The data in the 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-119

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-131F

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:55 PM

 

25

B66750

 

 

CSC-432

Discrete Algorithms

3

 

TC-206

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

 

20

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

 

 

 

 

 

35

 

 

 

3

 

TC-213

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

 

B78880

 

 

CSE-439

Special Topics in CSE

3

 

TC-206

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

 

22

J33486

 

 

 

 

 

 

 

 

 

 

 

 

 

Table 2.26. The data in the 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

76 Chapter 2

Introduction to Databases

 

Table 2.27. The data in the 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

3

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

schoolYear: VARCHAR2(20)

email: VARCHAR2(20)

The data types used in the StudentCourse table are:

s_course_id: NUMBER(4, 0)—precision = 4, scale = 0 (4-bit integer) Primary Key

student_id: VARCHAR2(10)

course_id: VARCHAR2(10)

credit: NUMBER(1, 0)—precision = 1, scale = 0 (1-bit integer)

major: VARCHAR2(40)

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