60
DSC209 Lab Manual: Introduction to Database Management (I) 2012 © IACC, ABU Zaria PAGE 1 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes FREE, NOT FOR SALE! Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester I Prepared and Delivered By M-Auwal Gene mcpn [email protected] @Iya Abubakar Computer Centre, Ahmadu Bello University, Zaria Nigeria Last Updated: March, 2012

Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

  • Upload
    lyquynh

  • View
    225

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 1 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Practical Laboratory Manual

For

DCS 209: Introduction to Database Management (I)

Diploma in Computer Science

Year II, Semester I

Prepared and Delivered

By

M-Auwal Gene mcpn

[email protected]

@Iya Abubakar Computer Centre, Ahmadu Bello University, Zaria – Nigeria

Last Updated: March, 2012

Page 2: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 2 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

CONTENTS INTRODUCTION ..........................................................................................................................................................4

JUST SOME FEW RULES PLEASE, BEFORE WE START ..............................................................................................5

Requirements Specs Review...................................................................................................................................7

1: Requirements Specification ...........................................................................................................................7

2: The Entities ....................................................................................................................................................8

3: The E-R Diagrams ...........................................................................................................................................8

4: The Relational Schema ............................................................................................................................... 10

5: The Data Dictionary .................................................................................................................................... 11

LAB SESSION 1 ......................................................................................................................................................... 13

Lab Session 1, Task 1: Starting Microsoft Access (2007) and identifying key items on the Microsoft Access

(2007) screen ....................................................................................................................................................... 13

Lab Session 1, Task 2: Creating the iacc-students-db database file ........................................................... 14

VISUAL OVERVIEW OF MICROSOFT ACCESS ENVIRONMENT .......................................................................... 16

Lab Session 1, Task 3: Creating tables for the IACC students records database ................................................ 17

Creating StatesTable .................................................................................................................................. 17

Lab Session 1, Task 4: Inserting some data into the tables ................................................................................ 19

End-of-Lab-Session Take-Home Assignment 1 (Worth 2%): ............................................................................ 24

LAB SESSION 2 ......................................................................................................................................................... 25

Lab Session 2, Task 1: Checking the correctness of your last take-home assignment ........................................ 25

Lab Session 2, Task 2: Creating the EnrollmentsTable for the IACC students records database .................. 25

LAB SESSION 3 ......................................................................................................................................................... 28

Lab Session 3, Task 1: Establishing table relationships and enforcing integrity constraints ............................... 28

Lab Session 3, Task 2: Establishing relationships between StudentsTable and LGAsTable ........................ 32

End-of-Lab-Session Take-Home Assignment 2 (Worth 4%): ................................................................................ 35

LAB SESSION 4 ......................................................................................................................................................... 36

Lab Session 4, Task 1: Inserting data into more tables ....................................................................................... 36

End-of-Lab-Session Take-Home Assignment 3 (Worth 4%): ................................................................................ 39

LAB SESSION 5 ......................................................................................................................................................... 41

Page 3: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 3 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Lab Session 5, Task 1: Generating reports from the StudentsTable via query design ................................... 41

Lab Session 5, Task 2: Running an SQL query against the StudentsTable...................................................... 45

Lab Session 5, Task 3: Writing the SQL query to answer question number (iii) in the requirements specs

document ............................................................................................................................................................. 48

LAB SESSION 6 ......................................................................................................................................................... 53

Lab Session 6, Task 1: Writing the SQL query to answer question number (iv) in the requirements specs

document ............................................................................................................................................................. 53

Lab Session 6, Task 2: Writing the SQL query to answer question number (v) in the requirements specs

document ............................................................................................................................................................. 55

Lab Session 6, Task 3: Writing the SQL query to answer question number (vi) in the requirements specs

document: ............................................................................................................................................................ 57

Lab Session 6, Task 4: Writing the SQL query to answer question number (vii) in the requirements specs

document ............................................................................................................................................................. 58

Lab Session 6, Task 5: Writing the SQL query to answer question number (viii) in the requirements specs

document ............................................................................................................................................................. 59

Page 4: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 4 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

INTRODUCTION

ELCOME TO the lab sessions for DCS 209 – Introduction to Database

Management (I). This laboratory manual is an important supplemental material

that accompanies the theoretical course notes for DCS 209; and the primary aim is

to enhance the practical coverage of concepts discussed in our theoretical class

discussions. While explaining the theory of relational database concepts and design

in our regular classes, we introduced the idea of developing a relatively simple database for

keeping the records of our Diploma programme students at IACC, ABU Zaria.

We have already come up with, and thoroughly

discussed, the requirements specifications,

entities, E-R diagrams, relational schema and

data dictionary for the proposed students’

database that we seek to develop. Now is the

time to translate all of that into a real database

system that can contain relevant data and meet

all the functionalities specified in the

requirements statements.

This is a hands-on, practical-intensive manual

that gives you step-by-step directions for

carrying out simple tasks that will show you how

to successfully build the simple students records

keeping database that we are interested in. As

you read, you should have a computer with

Microsoft Access 2007 to practice what you read.

I emphasize that you should by all means

endeavour to carry out the tasks yourself,

exactly as directed in this manual (and as you

shall be guided in the lab).

This material is divided into six chapters called

“Lab Sessions”, each of which has one or more

Tasks. You are advised to go through the manual

in sequence, starting with Lab Session 1, Task 1.

IMPORTANT NOTE: It is YOUR PERSONAL

RESPONSIBILITY to keep your files in a neat

and easily accessible manner. All tasks

described in this manual build upon preceding

tasks; so losing your file simply means you

would have to start all over again – on your

own! Also NOTE that all students’ lab works

shall be continuously assessed and graded

individually.

Best regards, and happy database development!

M-Auwal Gene mcpn @IACC, ABU Zaria March, 2012

W

Page 5: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 5 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

JUST SOME FEW RULES PLEASE, BEFORE WE START

1: Attendance Policy: Please note that all

students are expected to attend every Lab

Session on time. Punctuality is expected,

and is part of your cumulative

continuous assessment. In case of

unexpected events that make it

impossible for any student to attend Lab

Sessions, such students should contact me

(or any other Instructor in charge) via

phone call or send an SMS text message

briefly explaining why they would not be

in the Lab.

2: Extra Credit: Occasionally there are

opportunities for students to earn extra

credits for exceptionally excellent work

or enthusiastic attitude towards study in

the Lab. There is no guarantee that there

will be extra credit opportunities every

time; but whenever the opportunity

arises, all students will have an equal

chance of earning those extra credits.

Maximum extra credit obtainable by any

student is 5 points (out of 100).

3: Assignments: To evaluate students’

practical learning progress, one or more

take-home assignments shall be given to

students at the end of every Lab Session.

Those assignments will mostly be based

on the case study we are working on in

this manual; but may also sometimes

include work outside of our case study.

4: Make-Up and Late Policy: All

assignments that are handed in late will

be docked 2% per day that they are late,

unless arrangements have been made

at least 48 hours before the due date.

The term “LATE” refers to all assignments

that are turned in after the lab time on the

assignment’s due date. Please note that I

am not responsible for you not having

your personal laptop, or not having

Internet access, or not having access to

the lab computers to enable you do your

assignments. You will normally be given

freedom to do all practical assignments in

the lab if you properly approach the

Centre’s Operations Manager or any of

the Lab Support Staff on duty.

Page 6: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 6 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

5: Grading Policy: The following

grading policy shall apply during this

course (both theory and practical labs are

covered):

Please note that every student’s grade

totally depends on what he or she has

achieved during the course: the grades

will be earned, not given!

6: Lab Etiquette: Since we are a large

class in a relatively small lab, let us all

faithfully follow these four simple rules in

order to make life easy for everyone:

i. Be punctual. Coming in late disrupts

your fellow students. If you are

going to be late for a lab session,

perhaps you should not bother

coming to the lab, as you might not

be able to catch up.

ii. Do not leave the lab early unless it

is an emergency.

iii. No texting, phone calls or Internet

browsing during Lab Sessions.

iv. Kindly turn off cell phones, and

Internet access. If your phone rings

during a Lab Session or you are

seen browsing the ’Net during a Lab

Session, you shall be penalized –

and your penalty is to provide

snacks and drinks for the Instructor

at the next Lab Session.

Page 7: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 7 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Requirements Specs Review

Okay, now let’s get started but first, let us refresh our memories once again with the

requirements specifications, entities, E-R diagrams, relational schema and data dictionary

for our case study:

1: Requirements Specification

Assume we have spoken with the Director and staff of IACC and they have given us

the go-ahead to build a good database system for the Center according to the

specifications below:

(i) Build a database structure that will be capable of storing information about all students for the two Diploma programmes on offer presently (do not bother about building anything for the Centre’s staff, contractors, or equipment database).

(ii) Build it such that programmes and courses can be easily maintained (add new, modify existing ones or retire old ones but without deleting them).

(iii) Build it such that it will be possible to list out all students who have registered for a particular programme for a given academic session.

(iv) Build it such that it will be possible to list out all students who have registered for a particular course for a given semester of a given academic session.

(v) Build it such that it will be possible to list out all students who have paid or not paid their school fees for a given academic session.

(vi) Build it such that it will be possible to list out all the courses that a given student enrolled or registered for in a given semester of a given academic session, as well as that student’s scores in the exams of those courses.

(vii) Build it such that for a given semester of a given session, it will be possible to list out all students whose exam scores in a given course fall between a given score range (e.g. list all students who scored below 40 in DCS 209 or all students who scored above 75 in DCS 201 or all students who scored between 50-60 in DCS 206).

Page 8: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 8 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

(viii) Build it such that it will be possible to list out all students who come from a particular LGA or State of the country.

2: The Entities

PROGRAMME (ProgCode, ProgDescription, DateCreated, IsActive, DateRetired)

COURSE (CourseCode, CourseDescription, CreditUnits, DateCreated, IsActive, DateRetired) STUDENT (RegNumber, Surname, OtherNames, DOB, Gender, PhoneNumber, Email, LgaID, ProgCode, SessionAdmitted, DateAdmitted)

LGA (LgaID, LgaName, StateID)

STATE (StateID, StateName)

FEEPAYMENT (Session, RegNumber, AmountPaid, DatePaid)

ENROLLMENT (RegNumber, Session, Semester, CourseCode, TestScore, ExamScore)

3: The E-R Diagrams

A local govt area belongs to one and only one State; while a State may have one or many LGAs belonging to it.

A student belongs to or comes from one and only one LGA; a LGA may have zero or many students coming from it.

Page 9: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE 9 Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

A student is admitted into one and only one programme; For any semester of a session, a student registers or while a programme may have one or many students enrolls for one or more courses; and a given course may admitted for it. have no student or many students registered for it.

For any a session, a student pays one and only fee; and it is possible to have an instance where zero or many students have paid their fees for a given session.

It is possible to combine all of the above separate

E–R diagrams into one single unified diagram as

shown below:

Page 10: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

10

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

4: The Relational Schema

Page 11: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

11

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

5: The Data Dictionary

TABLE NAME ATTRIBUTE TYPE LENGTH REQUIRED (PK or FK) FK REFERENCED

TABLE

StudentsTable

RegNumber TEXT 15 Y PK Surname TEXT 25 Y OtherNames TEXT 25 Y Gender CHAR 1 Y DOB DATE/TIME Y Phone TEXT 15 Email TEXT 50 LgaID LONG ProgCode TEXT 8 Y DateAdmitted DATE/TIME Y

ProgrammesTable

ProgCode TEXT 8 Y PK ProgDescription TEXT 50 Y DateCreated DATE/TIME IsActive YES/NO Y DateRetired DATE/TIME

CoursesTable

CourseCode TEXT 6 Y PK CourseDescription TEXT 50 Y CreditUnits BYTE DateCreated DATE/TIME IsActive YES/NO Y DateRetired DATE/TIME

Page 12: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

12

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

ProgCoursesTable RowID LONG AutoNum Y PK ProgCode TEXT 8 Y FK ProgrammesTable CourseCode TEXT 8 Y FK CoursesTable

EnrollmentsTable

RowID LONG AutoNum Y PK RegNumber TEXT 15 Y FK StudentsTable CourseCode TEXT 8 Y FK ProgrammesTable Session TEXT 9 Y Semester BYTE TestScore BYTE ExamScore BYTE

FeePaymentsTable

RowID LONG AutoNum Y PK RegNumber TEXT 15 Y Session TEXT 9 Y AmountPaid CURRENCY Y DatePaid DATE/TIME Y

StatesTable StateID LONG AutoNum Y PK StateName TEXT 25 Y

LGAsTable LgaID LONG AutoNum Y PK LGAName TEXT 25 Y StateID LONG Y FK StatesTable

Page 13: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

13

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 1

OBJECTIVE: To quickly introduce the students to Microsoft Access (2007) application environment, get them to create and save their first database file, create a few tables and insert some sample data into the tables created.

TIME (APPROX): 2 hours, 15 minutes.

TOOLS REQUIRED: Microsoft Access (2007) and this Lab manual.

Lab Session 1, Task 1: Starting Microsoft Access (2007) and identifying key items on the Microsoft

Access (2007) screen

STARTING MICROSOFT ACCESS 2007

Microsoft Access is an application that belongs to the

Microsoft Office suite of applications and just like any

Office application, can be started from the Start menu on

the taskbar (Fig. 1):

- On the taskbar, click the Start button.

- On the Start menu, click All Programs, click

Microsoft Office, and then click Microsoft Access.

Fig 1: You can start Microsoft Access 2007 the same way

you start any normal Windows application.

Page 14: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

14

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

CREATING A DATABASE

When the Microsoft Access start-up screen comes up, it would look like the screenshot

shown in Fig. 2. Depending on how your own system is configured, there might be some

slight differences between what is shown on your screen and what is shown in Fig 2.

Fig 2: Microsoft Access 2007 provides a

library of prebuilt database solutions to

get you started quickly.

Lab Session 1, Task 2: Creating the iacc-students-db database file

To begin creating a new database, click the Blank Database icon on the screen and the

options for specifying the name and location of the new database you want to create

should appear around the lower right side of the screen (Fig. 3):

Page 15: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

15

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 3: To get started, click the Blank

Database icon and click the yellow folder

icon to specify where you want to save

your file.

Click the yellow folder icon so that you can browse or navigate to the Desktop and specify

the name of the database you want to create. Type iacc-students-db in the space

provided for file name and select Microsoft Office Access Databases (2000 – 2003 format)

for the file type and click OK (see Fig. 4):

Fig. 4: Specify the file name and file type. Before

you click OK, be sure to also specify Desktop as

the place where you want to save the file.

Page 16: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

16

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Microsoft Access should return you to the initial page where

you can then click the Create button to actually create the

database (Fig. 5):

Fig. 5: When you are returned to the initial startup page, click Create to actually create the database.

VISUAL OVERVIEW OF MICROSOFT ACCESS ENVIRONMENT

Fig. 6: The Microsoft Access 2007 main window, when first opened.

Page 17: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

17

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Lab Session 1, Task 3: Creating tables for the IACC students records database

Creating StatesTable

The StatesTable table has the following definition, from our data dictionary:

Field Type Constraints StateID Number AutoNum, PK StateName TEXT Required, Length = 25

To create the table, follow these steps:

1. If the initial default Table 1 is still open, change its view

from datasheet to design view by clicking the View

button on the Create tab on the Ribbon, then select

Design View (Fig. 7). Fig. 7

2. Microsoft Access will require you to save the file first before continuing.

Delete the default Table 1 and type StatesTable, then click OK (Fig. 8):

Fig. 8: Save the table with a proper

name.

3. The table’s layout should change and become as shown in Fig. 9. The default

field, ID, will always be there in every new table you create. It will always be

Page 18: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

18

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

automatically set as the primary key and it will always be an AutoNumber

data type.

4. Rename the ID field as StateID, but leave it as primary key and leave its data

type as AutoNumber.

Fig. 9: Rename the ID field, and add a new field

called StateName.

5. Add the StateName field, make it TEXT, and change the length from 255 to 25.

Also change the Required option from No to Yes; and change the Allow Zero

Length option from Yes to No (Fig. 10):

Fig. 10: Pay attention to the items

circled in red and change them as

described.

Page 19: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

19

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

6. Save the table and close it. Now you can create the LGAsTable and

ProgrammesTable following exactly the same steps as you just did for the

StatesTable. Take care to type the field names correctly and also specify

their data types correctly.

7. You shall be guided in the lab by your Instructor.

Lab Session 1, Task 4: Inserting some data into the tables

(a) Inserting data into StatesTable

As you know by now, Microsoft Access can display tables in Design view, Datasheet view,

PivotTable view or PivotChart view. The Datasheet view shows a table’s contents in rows

(records) and columns (fields). Each column is headed by a field name inside a field

selector, and each row has a record selector to its left (see Fig. 11):

Fig. 11: Entering data into the StatesTable.

Page 20: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

20

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Clicking a field selector or record selector selects an entire column or row (respectively),

which you can then manipulate. A field selector is also called a column selector, and a

record selector is also called a row selector.

To enter data into the StatesTable, open it in Datasheet view and type the field values

below the StateName column only. You don’t have to (in fact, you are not supposed to)

type anything under the AutoNumber StateID fields, as Access will automatically and

correctly filled the AutoNumber values for you. Here is the complete list of data you

should enter into the StatesTable:

StateID StateName StateID StateName 1 ABIA 21 KATSINA 2 ADAMAWA 22 KEBBI 3 AKWA-IBOM 23 KOGI 4 ANAMBRA 24 KWARA 5 BAUCHI 25 LAGOS 6 BAYELSA 26 NASSARAWA 7 BENUE 27 NIGER 8 BORNO 28 OGUN 9 CROSS RIVER 29 ONDO 10 DELTA 30 OSUN 11 EBONYI 31 OYO 12 EDO 32 PLATEAU 13 EKITI 33 RIVERS 14 ENUGU 34 SOKOTO 15 FCT ABUJA 35 TARABA 16 GOMBE 36 YOBE 17 IMO 37 ZAMFARA 18 JIGAWA 19 KADUNA 20 KANO

Page 21: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

21

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

When you finish entering data, your StatesTable should look similar to the one shown in

Fig. 12.

Fig. 12: The StatesTable, with lots of data entered.

(b) Inserting data into LGAsTable

Entering data into the LGAsTable follows the same principle as entering data into the

StatesTable. You open it Datasheet View, and start entering your data column-by-

column, one row at a time. The LGAsTable is related to the StatesTable via the

StateID. So for every local government name that you wish to enter, you need to first

know its corresponding StateID. To know the StateID for any local government, you

will need to first know which state the local government belongs to, then look up the

Page 22: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

22

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

StateID in the StatesTable and then come back and

insert that StateID along with the local government name

in the LGAsTable.

So, to insert a local government called Kaiama (which is in

Kwara State) for example, we’d first look up the StateID

for Kwara in the StatesTable, which shows that Kwara’s

ID is 24 (see Fig. 13); then we would type Kaiama for the

LgaName and 24 for the StateID in LGAsTable. Names of

other local government areas in Kwara State can be

similarly added, each time specifying 24 as the StateID.

Fig. 13: Kwara has an ID of 24 in the StatesTable.

Fig. 14: Entering the first data in the

StatesTable.

Here is the list of local government data for Kwara State and for Nassarawa State that you

should enter into the LGAsTable:

Page 23: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

23

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

KWARA STATE NASSARAWA STATE

LgaID StateID LgaName LgaID StateID LgaName 1 24 ASA 19 26 AKWANGA 2 24 BARUTEN 20 26 AWE 3 24 EDU 21 26 DOMA 4 24 EKITI 22 26 KARU 5 24 IFELODUN 23 26 KEANA 6 24 ILORIN EAST 24 26 KEFFI 7 24 ILORIN SOUTH 25 26 KOKONA 8 24 ILORIN WEST 26 26 LAFIA 9 24 ILORIN SOUTH 27 26 NASARAWA 10 24 ILORIN WEST 28 26 NASARAWA-EGGON 11 24 IREPODUN 29 26 OBI 12 24 ISIN 30 26 TOTO 13 24 KAIAMA 31 26 WAMBA 14 24 MORO 15 24 OFFA 16 24 OKE-ERO 17 24 OYUN 18 24 PATEGI

(c) Inserting data into ProgrammesTable

We shall insert only four programmes in the ProgrammesTable, as shown below:

ProgCode ProgDescription DateCreated IsActive DateRetired

DCS Diploma in Computer Science 01-Nov-2005 Yes [leave blank] DCE Diploma in Computer Science 01-Nov-2005 Yes [leave blank] EFCC Diploma in E-Crime Forensics 01-Nov-2005 Yes [leave blank] DGE Diploma in GSM Engineering 01-Nov-2005 Yes [leave blank]

Page 24: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

24

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

GOOD TO KNOW

Your practical take-home assignments

shall be assessed and graded when you

turn them in; and your scores will be

recorded. To each lab activity and take-

home assignment, a maximum point

obtainable is attached and as our

grading policy showed on page 7 of this

manual, all of this will eventually add up

to 20% of your total scores in this

course.

Students are, therefore, strongly advised

once more to take all hands-on lab tasks

and take-home assignments seriously.

This particular take-home assignment is

worth 02%.

End-of-Lab-Session Take-Home Assignment 1

(Worth 2%): Your task in this first assignment is to

create the four tables below, following the data

dictionary specified on page 12 of this manual. The

four tables you should to create are:

(i) StudentsTable,

(ii) FeePaymentsTable,

(iii) CoursesTable, and

(iv) ProgCoursesTable

Page 25: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

25

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 2

OBJECTIVE: To go over students’ take-home assignment issued in the previous Lab Session

and correct all errors and address any challenges reported by students while doing that

assignment. The Instructor is required to go round the work of each student one by one

and publicly point out and correct any errors found so that other students with similar

challenges can learn about them.

TIME (APPROX): 2 hours, 15 minutes.

TOOLS REQUIRED: Microsoft Access (2007), students’ submitted files from the previous

take-home assignment, and this Lab manual.

Lab Session 2, Task 1: Checking the correctness of your last take-home assignment

(i) Instructor should start with the first student (by registration number) and

inspect the student’s tables one by one.

(ii) For each table, the field names, data type and field lengths should be checked

and corrected.

(iii) Students are strongly advised to pay attention and participate actively during

this lab session.

Lab Session 2, Task 2: Creating the EnrollmentsTable for the IACC students records

database

The EnrollmentsTable table has the following definition, from our data dictionary:

Field Type Required Constraints Reference Table RowID LONG AutoNum Y PK

RegNumber TEXT 15 Y FK StudentsTable CourseCode TEXT 8 Y FK ProgrammesTable Session TEXT 9 Y Semester BYTE TestScore BYTE ExamScore BYTE

Page 26: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

26

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

To create the table, follow these steps:

1. Go to the Create menu and select Table. When the

default Table 1 opens, change its view from datasheet to

design view by clicking the View button on the Create tab

on the Ribbon, then select Design View (Fig. 15). Fig. 15

2. Access will require you to save the file first before continuing. Delete the

default Table 1 and type EnrollmentsTable, then click OK (Fig. 16):

Fig. 16: Save the table with a proper

name.

3. The table’s layout should change to design view and, as usual, the default field,

ID, will always be there. It will always be automatically set as the primary key

and it will always be an AutoNumber data type.

4. Rename the ID field as RowID, but leave it as primary key and leave its data

type as AutoNumber.

Page 27: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

27

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

5. Add the RegNumber field, make it TEXT, and change the length from 255 to 15.

Also change the Required option from No to Yes; and change the Allow

Zero Length option from Yes to No (Fig. 17):

Fig. 17: Pay attention to the items circled in red and change them as described.

6. Create all the other fields for the EnrollmentsTable following exactly the

same steps as you did for the other tables you have worked with. Take care to

type the field names correctly and also specify their data types correctly.

7. Save your work and get ready for Lab Session 3

Page 28: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

28

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 3

OBJECTIVE: To show students how to establish relationships among tables and enforce

referential integrity.

TIME (APPROX): 2 hours, 0 minutes.

TOOLS REQUIRED: Microsoft Access (2007), the iacc-students-db.mdb file, and this

Lab manual.

Lab Session 3, Task 1: Establishing table relationships and enforcing integrity constraints

During theory class lectures, we have extensively discussed what table relationships are

and their importance in relational database design (and implementation). In this Lab

Session, we shall learn to create relationships among the various tables we have created,

following the guidelines specified in the requirements spec (see the beginning pages of

this manual).

We start with the relationship between LGAsTable and StatesTable.

Both the LGAsTable and StatesTable have a field called StateID. StateID is the

primary key in StatesTable and it is designated as AutoNumber. In the LGAsTable

however, StateID is a foreign key, referencing StateID in the StatesTable.

To explicitly define this relationship in Microsoft Access (2007), follow these steps:

1. Close all opened tables, then

click Database Tools on the

menu bar, followed by

Relationships (see Fig. 18)

Fig. 18: Click Database Tools on the

menu bar, then click Relationships.

Page 29: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

29

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

2. The Relationships window will open, click on Show Table to bring up the

Show Table dialog (see Fig. 19)

Fig. 19: Click Show Table in the Design tab of the Relationships window.

3. Double-click the StatesTable to bring up its window; and do the same for

LGAsTable, too. Now you can close the Show Table dialog by clicking the

Close button (see Fig. 20):

Fig. 20: Double-click

StatesTable and then

LGAsTable to put them in

the Relationships design

window.

Page 30: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

30

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

4. To now establish a relationship between StatesTable and LGAsTable, click

the StateID field on StatesTable and, without releasing your mouse

button, drag your mouse from StatesTable towards LGAsTable until the

mouse icon is directly above StateID on the LGAsTable, then release your

mouse button. In other words, just drag StateID from StatesTable and

drop it on StateID on LGAsTable (see Fig. 21):

Fig. 21: Drag StateID field from StatesTable and drop it on StateID field on LGAsTable.

5. The Edit Relationships dialog comes up, where you can specify whether to

enforce referential integrity or not. Through this dialog, you can also specify

whether to automatically cascade update or deletion of related records

through checkboxes. Notice that Microsoft Access already knows that there

would exist a 1:N relationship between the StatesTable and LGAsTable

through the StateID attribute. Just check the Enforce Referential Integrity

checkbox and click Create (see Fig. 22):

Page 31: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

31

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 22: Click the Enforce Referential Integrity checkbox to check it, and then click

the Create button.

6. If all goes well, your relationships

window should now look like the one

shown in Fig. 23, meaning that you

have successfully established a

relationship between StatesTable

and LGAsTable. Fig. 23: The relationship is now established.

7. Click the save icon on the ribbon and close the relationship design window.

Page 32: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

32

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Lab Session 3, Task 2: Establishing relationships between StudentsTable and

LGAsTable

The LGAsTable is related to StatesTable through the StateID attribute; and it is also

related to StudentsTable through the LgaID attribute. To tell Microsoft Access that this

relationship exists and you want the constraint to be enforced, you would open the

relationships design window once again and add StudentsTable, the drag LgaID from

LGAsTable and drop it on LgaID on StudentsTable. To achieve all of these, follow these

steps:

1. With the Relationships Tool window

opened in design mode, click on Show

Table to bring up the Show Table dialog

(see Fig. 24).

Fig. 24: Click Show Table in the Design tab of the

Relationships window.

2. Double-click StudentsTable in the Show Table dialog so that the StudentsTable

now appears in the relationships design window along with StatesTable and

LGAsTable which already have their relationship defined (see Fig. 25):

Fig. 25: Put the StudentsTable in the

relationships design window by double-

clicking on it in the Show Table dialog.

Page 33: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

33

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

3. Establish a relationship between LGAsTable and StudentsTable by dragging

LgaID from LGAsTable and drop it on LgaID on StudentsTable (see Fig. 26):

Fig. 26: Drag LgaID from LGAsTable and drop it on LgaID in StudentsTable.

4. When the Edit Relationships dialog comes up, check the Enforce Referential

Integrity checkbox and click

Create (see Fig. 27):

Fig. 27: Check the Enforce Referential

Integrity box and click Create.

Page 34: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

34

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

5. If all goes well, your relationships window should now look like the one shown in

Fig. 28, meaning that you have successfully established a relationship between

LGAsTable and StudentsTable:

Fig. 28: We now have an E-R diagram showing the relationships between the three tables.

6. Click the save icon on the ribbon and close the relationship design window.

Now you can create the relationships for all the tables in the iacc-students-db

database following the above general steps and using the data dictionary as a guide. Take

care to follow the steps correctly and also use the correct fields in the various tables to

establish the relationships. You shall be guided in the lab by your Instructor and if all goes

well, your complete E-R diagram for the database should look like the one shown in Fig.

29:

Page 35: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

35

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

GOOD TO KNOW

Your first take-home assignment was

worth 02%, while this one is worth 04%;

giving a total of 06% so far.

Fig. 29: The complete E-R diagram for our iacc-students-db database.

End-of-Lab-Session Take-Home Assignment 2 (Worth 4%): Your Instructor will divide

you into groups of four or five students per group. Each group shall be required to fill in

data into the LGAsTable according to the States the group is assigned.

For example, Group 1 might be instructed to find out all the local governments in Lagos,

Katsina and Adamawa States and correctly feed in all those local governments into the

LGAsTable along with their respective StateIDs. Group 2 might be required to get LGA data

for Oyo, Abia and Kano States; while Group 3 might be told to work on FCT, Niger and

Anambra.

All students should endeavour to be in the Lab when

the groups will be created and assigned their

respective tasks. Students who miss that Lab Session

will be missing 4%.

Page 36: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

36

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 4

OBJECTIVE: To expose students to the tedium of repetitive data entry tasks, involving

different data types and different referential integrity constraints.

TIME (APPROX): 2 hours, 0minutes.

TOOLS REQUIRED: Microsoft Access (2007), the iacc-students-db.mdb file, and this

Lab manual.

Lab Session 4, Task 1: Inserting data into more tables

In Lab Session 1, Task 4, you learned how to insert some data into some of the tables

you’ve created. You actually inserted some data into the StatesTable, LGAsTable and

ProgrammesTable. In this Lab Session, you shall be inserting more data into more tables.

(a) Inserting data into CoursesTable – Insert the following data into CoursesTable:

CourseCode CourseDescription CreditUnits DateCreated DCE211 MATLAB 3 13-Jan-2007 DCS101 Information Technology 3 13-Jan-2007 DCS102 Information Technology (II) 2 12-Jul-2007 DCS103 Discrete Structures 2 13-Jan-2007 DCS104 Discrete Structures (II) 3 12-Jul-2007 DCS106 Intro to Programming Languages 3 12-Jul-2007 DCS109 Intro to Web Apps 3 13-Jan-2007 DCS110 Social and Professional Issues 3 12-Jul-2007 DCS112 Intro to Computer Architecture 3 12-Jul-2007 DCS203 Operating Systems 3 13-Jan-2007 DCS205 Introduction to Networking 3 11-Jan-2007 DCS207 Web Applications Engineering 3 13-Jan-2007 DCS209 Introduction to Databases (I) 3 11-Jan-2007 DCS210 Introduction to Databases (II) 3 12-Jul-2007 MTH102 Coordinate Geometry 3 12-Jul-2007 MTH201 Calculus and Trigonometry 2 13-Jan-2007 STA107 Statistics 3 13-Jan-2007

Page 37: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

37

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

(b) Inserting data into ProgCoursesTable – Insert the following data into

ProgCoursesTable:

RowID ProgCode CourseCode 1 DCS DCS207 2 DCS DCS101 3 DCS MTH102 4 DCS DCS103 5 DCE DCE211 6 DCE DCS103 7 DCS DCS104 8 DCE MTH201 9 DCS DCE211 10 DCS DCS109 11 DCS DCS102 12 DCS DCS106 13 DCS DCS110 14 DCE DCS110 15 DCE DCS203 16 DCS DCS203 17 DCS STA107 18 DCS DCS205 19 DCE DCS205 20 DCE DCS112 21 DCS DCS112

(c) Inserting data into StudentsTable – Insert the following data into StudentsTable:

RegNumber Surname OtherNames Gender DOB ProgCode SessionAdmitted DateAdmitted

99003 GENE M-Auwal M 14-Jun-1983 DCS 2009/2010 07-Jan-2010

22002 MUSA Haliru M 14-Jun-1989 DCE 2009/2010 10-Oct-2010

55660 ATANDA Ramota F 14-Jun-1991 DCS 2010/2011 19-Sep-2010

76331 ABAJI Salami M 14-Mar-1991 DCE 2009/2010 14-Jan-2010

88778 VICTOR Esther Titi F 21-Jun-2011 DCE 2009/2010 17-Nov-2009

10101 SULE Lamido Abubakar M 14-Jun-1967 DCS 2009/2010 14-Oct-2009

33009 HASSAN Amina Ladidi F 14-Jun-1993 DCE 2010/2011 14-Jan-2011

53530 JOSEPH Falmata F 10-Apr-1993 DCS 2010/2011 14-Jan-2011

17757 ABUBAKAR Ribadu M 26-Feb-1992 EFCC 2010/2011 16-Nov-2010

90070 ZAKARI Imran M 25-Sep-1992 DCS 2010/2011 16-Nov-2010

Page 38: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

38

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

99666 AJETUMOBI Tosin Ruqayyat F 20-Oct-1994 DGE 2010/2011 05-Dec-2010

22994 MAHMUD Zubair Yusuf M 16-Jul-1993 EFCC 2009/2010 05-Dec-2009

16604 AREMU OKIKI Olusola M 16-Jul-1993 DCS 2010/2011 05-Dec-2010

68050 BATURE UMMI Yarinya F 16-Jul-1993 DCS 2010/2011 05-Dec-2010

77477 SULEIMAN Kaka Alimi M 23-Mar-1992 DCS 2010/2011 05-Dec-2010

54555 DANIEL Daisy F 11-Apr-1992 DCS 2010/2011 05-Nov-2010

33221 SULEIMAN Emeka M 10-Sep-1993 DCE 2009/2010 03-Oct-2009

86112 OLORUNTOBA Abidemi M 02-Oct-1991 DCS 2009/2010 22-Oct-2009

53329 YAHYA Haruna Fegi M 07-Jul-1997 DCE 2010/2011 30-Aug-2010

67435 OKECHUKWU Amarachi Joy F 18-Jun-1995 DGE 2009/2010 10-Oct-2009

77223 RUFAI Abdulrasheed M 30-Aug-1994 DCS 2009/2010 22-Sep-2009

82110 AZEEZ Kola Olatunde M 12-May-1995 EFCC 2009/2010 09-Nov-2009

29445 GARBA Ibahim Gunu M 05-Apr-1994 DCS 2010/2011 23-Dec-2010

49903 KILANI Titilayo Omowumi F 12-Dec-1992 DCS 2009/2010 09-Oct-2009

47838 MUH’D Yunus Danbazau M 16-Feb-1994 DGE 2009/2010 07-Dec-2009

93377 KABIR Zakari Yau M 18-Jun-1995 DCS 2009/2010 09-Nov-2009

52688 SALISU Abdallah Bilal M 24-Mar-1993 DCS 2009/2010 16-Oct-2009

29005 AKINSEYE Oluwakemi F 19-Aug-1995 EFCC 2010/2011 12-Jan-2011

77311 SULEIMAN Salami M 12-Dec-1992 DCS 2009/2010 13-Sep-2009

75022 MAHMUD Musa Toro M 28-Jan-1994 DCS 2009/2010 17-Nov-2009

20905 IDRIS Hajara Tunau F 18-Mar-1993 DCS 2009/2010 15-Oct-2009

90333 ZUBAIR Zainab F 10-Jul-1995 DCS 2009/2010 15-Oct-2009

62116 DALHATU Jikan-Halidu M 24-Sep-1993 DCS 2009/2010 15-Oct-2009

29933 FASHOLA Adisa Kuranga M 30-Jan-1994 DCE 2009/2010 15-Oct-2009

19887 ORJI Chukudi Sunday M 21-Feb-1993 DCS 2009/2010 15-Oct-2009

39439 ABDULSALAM J. Ogrima M 28-Dec-1993 DCS 2009/2010 07-Sep-2009

91152 JOHN Salamatu F 16-Aug-1995 DGE 2009/2010 07-Sep-2009

38777 BRAIMOH Husseinah F 14-Jul-1994 EFCC 2009/2010 10-Sep-2009

40055 YAHUZA Idris Saleh M 08-Nov-1992 DCS 2009/2010 17-Oct-2009

19995 GABRIEL Ilesanmi Emeka M 20-Jul-1993 DCS 2010/2011 11-Nov-2010

83339 DAUDA Justina F 14-Apr-1992 DCS 2009/2010 06-Oct-2009

67488 PETER Omorigbue M 22-May-1994 DCS 2009/2010 06-Oct-2009

55995 IKEKHUA Juliana F 31-Dec-1992 DCS 2009/2010 02-Oct-2009

31103 MUSA Abubakar M 25-Mar-1994 DCE 2010/2011 10-Nov-2010

Page 39: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

39

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

GOOD TO KNOW

Your first and second take-home

assignments were altogether worth 06%,

while this one is worth 04%; giving a

total of 10% so far.

End-of-Lab-Session Take-Home Assignment 3

(Worth 4%): Your task in this assignment is to

individually populate the EnrollmentsTable and

FeePaymentsTable with the data given below.

1: Data for EnrollmentsTable:

RowID RegNumber CourseCode AcadSession Semester TestScore ExamScore 99003 DCS101 2009/2010 1 4 69 99003 DCS103 2009/2010 1 7 55 99003 DCS109 2009/2010 1 2 42 76331 DCS101 2009/2010 1 5 33 77223 DCS106 2009/2010 1 3 61 77223 DCS209 2009/2010 1 5 58 22002 DCS101 2009/2010 1 71 22002 DCS106 2009/2010 1 2 39 82110 DCS209 2009/2010 1 3 66 10101 DCS101 2009/2010 1 6 44 10101 DCS106 2009/2010 1 2 53 10101 DCS209 2009/2010 1 4 59 88778 DCS101 2009/2010 1 4 28 88778 DCS106 2009/2010 1 6 41 22994 DCS209 2009/2010 1 49 20905 DCS209 2009/2010 1 5 49903 DCS209 2009/2010 1 3 32 67488 DCS209 2009/2010 1 7 62 39439 DCS209 2009/2010 1 2 49 83339 DCS209 2009/2010 1 4 43 55995 DCS209 2009/2010 1 5 52 75022 DCS209 2009/2010 1 4 38 99003 DCS209 2009/2010 1 7 61 99003 DCS112 2009/2010 1 1 24

Page 40: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

40

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

2: Data for FeePaymentsTable:

RowID RegNumber AcadSession AmountPaid DatePaid 1 90070 2010/2011 40,000.00 17-Oct-2010 2 10101 2010/2011 50,000.00 12-Dec-2010 3 22002 2010/2011 50,000.00 22-Oct-2010 4 90070 2011/2012 50,000.00 11-Nov-2011 5 33221 2011/2012 50,000.00 12-Sep-2011 6 33221 2010/2011 45,000.00 14-Dec-2010 7 54555 2009/2010 50,000.00 22-Feb-2010 8 99003 2009/2010 50,000.00 14-Dec-2010 9 88778 2009/2010 50,000.00 14-Dec-2010 10 17757 2010/2011 50,000.00 13-Jan-2011 11 99666 2010/2011 50,000.00 22-Dec-2010 12 22994 2009/2010 50,000.00 25-Nov-2009 13 77477 2010/2011 50,000.00 15-Feb-2011 14 67435 2009/2010 45,000.00 01-Dec-2009 15 49903 2009/2010 50,000.00 23-Nov-2009 16 93377 2009/2010 50,000.00 15-Dec-2009 17 29005 2010/2011 50,000.00 30-Nov-2010 18 20905 2009/2010 50,000.00 09-Sep-2009 19 29933 2009/2010 50,000.00 02-Dec-2009 20 91152 2009/2010 50,000.00 13-Dec-2009 21 38777 2009/2010 50,000.00 16-Nov-2009 22 31103 2010/2011 50,000.00 28-Nov-2010 23 55995 2009/2010 50,000.00 17-Jan-2010 24 62116 2009/2010 50,000.00 12-Dec-2009 25 39439 2009/2010 50,000.00 12-Jan-2010

Page 41: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

41

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 5

OBJECTIVE: To demonstrate how various reports can be generated from relational

database tables using the built-in Query Design of Microsoft Access (2007), as well as using

SQL statements directly.

TIME (APPROX): 2 hours, 30 minutes.

TOOLS REQUIRED: Microsoft Access (2007), the iacc-students-db.mdb file, and this

Lab manual.

Lab Session 5, Task 1: Generating reports from the StudentsTable via query design

We shall begin by querying the StudentsTable to list out all students in that table, then

we shall eventually go deeper and see how we can use SQL to filter out specific details of

the reports as we desire. Follow these steps to list out all records in the StudentsTable:

(i) Close all opened tables, click the Create tab, then click Query Design (Fig. 30).

Fig. 30: Starting the query design is easy and straight-forward.

Page 42: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

42

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

(ii) The query design window will open, with the Show Table dialog on top (Fig. 31):

Fig. 31: The Show Table dialog opens when you

start the query design.

(iii) The Show Table dialog allows

you to pick the tables you wish to generate

your query from. You can pick one or more

tables, but since we are interested in

showing the contents of just the

StudentsTable only, select that table and

click Add. An instance of the

StudentsTable will appear in the query

design window, with all its attributes

(circled red in Fig. 32). Close the Show Table

dialog.

Fig. 32: Double-click StudentsTable in the Show Table dialog, and StudentsTable will appear in the query design window along with its fields.

Page 43: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

43

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

(iv) Now, we want to list out all records in the table and we want our list to show

every student’s registration number, surname, other names, gender, date of birth,

programme admitted for and session admitted. To indicate those fields that we want to

show on our report, double-click the name of the field in the StudentsTable window in

the query design, and you will

immediately see that field’s name

appearing selected in the lower pane of

the query design window (Fig. 33):

Fig. 33: To indicate which fields you want to show in

your report, double-click the names of the fields one

after the other and make sure they appear in the

lower panel of the query design window.

(v) Repeat the process of locating a field name in the table attributes window and

double-clicking on the field’s name, scrolling as necessary, until all of the following field

names are double-clicked and they all appear selected in the lower pane of the query

design window: RegNumber, Surname,

OtherNames, Gender, DOB, ProgCode

and SessionAdmitted (Fig. 34).

Page 44: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

44

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 34: Click the Run command to see the results of your query.

(vi) Click the Run command on the Design tab (Fig. 35 above) to see the result o

your query. If all goes well, you should be able to see an output similar to the one shown

in Fig. 35:

Fig. 35: The query returns the list of all students in the StudentsTable.

(vii) Save the query by clicking the save icon on

the ribbon, and when prompted for a name for the

Page 45: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

45

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

query, delete the default Query1 and type AllStudentsQuery, then click OK (see Fig. 36):

Fig. 36: Save the query as AllStudentsQuery.

Lab Session 5, Task 2: Running an SQL query against the StudentsTable

Now we want to use SQL to tweak the results returned by our query design in the last task.

The result of the last task is actually generated by the SQL that you are already familiar

with; and you can open the underlying SQL command and tweak it to give you precisely

what you want.

Let’s assume we want to see only students that are female (gender = ‘F’) in the

StudentsTable, then we would need to adjust Task 1’s SQL command to filter the output.

To see the underlying SQL command that generated Task 1’s output and then tweak it,

click the SQL icon on the status bar at the extreme bottom right of the screen (see Fig. 37).

You will immediately see the SQL codes for the output, as shown in Fig. 38:

Page 46: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

46

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, StudentsTable.Surname,

StudentsTable.OtherNames, StudentsTable.Gender,

StudentsTable.DOB, StudentsTable.ProgCode,

StudentsTable.SessionAdmitted FROM StudentsTable;

Fig. 37: Locate the SQL icon at the bottom right of the status bar and click it to open the SQL codes for the query.

Fig. 38: The SQL codes of AllStudentsQuery query.

The SQL command there reads:

And we can easily modify it to show us only female students by adding the familiar

WHERE clause, like so:

Page 47: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

47

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, StudentsTable.Surname,

StudentsTable.OtherNames, StudentsTable.Gender,

StudentsTable.DOB, StudentsTable.ProgCode,

StudentsTable.SessionAdmitted FROM StudentsTable

WHERE Gender = 'F';

If you click the Run command again with the above modification, you should be able to see

an output similar to the one shown in Fig. 39:

Page 48: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

48

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 39: We are now seeing only female students because we’ve filtered the output using the familiar WHERE clause in the SQL command.

Lab Session 5, Task 3: Writing the SQL query to answer question number (iii) in the

requirements specs document

Page 49: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

49

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

You will recall that in our requirements specs document, the third requirement want s to

build the database such that it will be possible to list out all students who have registered

for a particular programme for a given academic session.

Well, we have built the database, created the tables, established the relationships and

constraints, and also populated the tables. Now let’s see how we can list out all students

who have registered for a particular programme for a given academic session:

1. Close all opened tables, click the Create tab, then click Query Design (Fig. 40).

Fig. 40: Start with the query design.

2. The query design window will

open with the Show Table dialog as

usual (Fig. 41). Close the Show

Table dialog, so that your query

design window now looks like the

one shown in Fig. 42.

Fig. 41: The query design window opens

with the Show table dialog.

Page 50: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

50

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 42: Click SQL View on the menu bar to open the window where you can type

your SQL commands.

3. Click SQL View on the menu bar to open the query design window in SQL

mode, where you may begin to type your SQL commands (see Fig. 43):

Fig. 43: Query design is

now opened in SQL

command mode.

Page 51: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

51

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT RegNumber, Surname, OtherNames, Gender, ProgCode,

SessionAdmitted

FROM StudentsTable

WHERE ProgCode = 'DCS' AND SessionAdmitted = '2009/2010'

ORDER BY Surname;

4. Delete the default SELECT; command in the SQL window and type the

following SQL command that will list out all students who have registered for

a particular programme (DCS) for a given academic session (2009/2010):

Your SQL query window should look similar to the one shown in Fig. 44:

Fig. 44: Type your SQL statement carefully, and click the Run command to see the output.

Page 52: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

52

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

5. Click the Run command on the menu bar and if all goes well, you should be

able to see an output similar to the one shown in Fig. 45:

Fig. 45: Output of the query to list out all students who registered for

a particular programme (DCS) in a given academic session (2009/2010).

6. Click the save icon on the ribbon and save this query as Question3.

Fig. 46: Save the query with a proper name.

Page 53: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

53

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

LAB SESSION 6

OBJECTIVE: To continue our exploration of how various reports can be generated from

relational database tables using SQL statements. We shall be answering more of the

requirements specs questions.

TIME (APPROX): 2 hours, 0 minutes.

TOOLS REQUIRED: Microsoft Access (2007), the iacc-students-db.mdb file, and this

Lab manual.

Technique: For each of the requirement statements in the requirements specs document,

the SQL to generate the required report shall be given and the student is expected to enter

and run the SQL statements, following the procedures described in the previous Lab

Session. Each SQL statement should then be saved as Question4 (for the fourth

requirement statement), Question5 (for the fifth requirement statement) and so on.

The Instructor will go round continuously to assess and grade each student’s work in the

Lab. Please note that the Instructor may decide to cover all of the tasks described in this

session in the lab or give some out as take-home assignments. At any rate, the tasks in this

last session of this manual constitute 10% of your practical C.A.; so you are strongly

advised to take all the tasks seriously and participate fully in their completion; else

you could be losing 10% of your total grade for this course!

Lab Session 6, Task 1: Writing the SQL query to answer question number (iv) in the

requirements specs document: “List out all students who have registered for a particular

course for a given semester of a given academic session.”

Page 54: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

54

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, Surname, OtherNames,

Gender, ProgCode, EnrollmentsTable.CourseCode,

EnrollmentsTable.AcadSession, EnrollmentsTable.Semester

FROM StudentsTable INNER JOIN EnrollmentsTable ON

StudentsTable.RegNumber = EnrollmentsTable.RegNumber

WHERE CourseCode = 'DCS209' AND AcadSession = '2009/2010'

AND Semester = 1 ORDER BY Surname;

The above query lists out all students who registered for DCS 209 in the first semester of

2009/2010 academic session. If done correctly, the query should produce an output

similar to the one shown in Fig. 47:

Fig. 47: Output of the query to list out all students who registered for DCS 209 in the first semester of 2009/2010 academic session

When done, save the above query as Question4.

Page 55: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

55

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, Surname, OtherNames, Gender,

ProgCode, SessionAdmitted, FeepaymentsTable.AmountPaid, DatePaid,

AcadSession AS SessionPaidFor

FROM StudentsTable INNER JOIN FeepaymentsTable ON

StudentsTable.RegNumber = FeepaymentsTable.RegNumber

WHERE AcadSession='2009/2010' ORDER BY Surname;

Lab Session 6, Task 2: Writing the SQL query to answer question number (v) in the

requirements specs document: “List out all students who have paid or not paid their school

fees for a given academic session.”

The above query lists out all students who paid their fees for 2009/2010 academic

session. If done correctly, the query should produce an output similar to the one shown in

Fig. 48:

Fig. 48: Output of the query to list out all students who paid their fees for 2009/2010 academic session.

Page 56: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

56

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT DISTINCT RegNumber, Surname, OtherNames, Gender,

ProgCode, SessionAdmitted

FROM StudentsTable

WHERE (((StudentsTable.RegNumber) Not In (SELECT

FeepaymentsTable.RegNumber FROM FeepaymentsTable WHERE

AcadSession='2009/2010'))

AND SessionAdmitted='2009/2010');

When done, save the above query as Question5a.

The above query lists out all students who were admitted for 2009/2010 academic

session and have not paid their fees for 2009/2010 academic session. If done correctly,

the query should produce an output similar to the one shown in Fig. 49:

Fig. 49: Output of the query to list out all students who have not paid their fees for 2009/2010 academic session.

Page 57: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

57

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, Surname, OtherNames, Gender,

EnrollmentsTable.CourseCode, AcadSession, Semester, TestScore,

ExamScore, (TestScore + ExamScore) AS TotScore

FROM StudentsTable INNER JOIN EnrollmentsTable ON

StudentsTable.RegNumber = EnrollmentsTable.RegNumber

WHERE StudentsTable.RegNumber ='99003' AND

AcadSession = '2009/2010' AND Semester = 1;

When done, save the above query as Question5b.

Lab Session 6, Task 3: Writing the SQL query to answer question number (vi) in the

requirements specs document: “List out all the courses that a given student enrolled or

registered for in a given semester of a given academic session, as well as that student’s scores

in the exams of those courses.”

The above query lists out all the courses that a given student (in this case, we chose the

student with Reg. Number 99003) enrolled or registered for in a given semester (we chose

first semester in this case) of a given academic session (we chose 2009/2010 session for

this example), as well as that student’s scores in the exams of those courses. If done

correctly, the query should produce an output similar to the one shown in Fig. 50:

Page 58: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

58

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, Surname, OtherNames, Gender,

EnrollmentsTable.CourseCode, AcadSession, Semester, ExamScore

FROM StudentsTable INNER JOIN EnrollmentsTable ON

StudentsTable.RegNumber = EnrollmentsTable.RegNumber

WHERE AcadSession = '2009/2010' AND Semester = 1 AND

EnrollmentsTable.CourseCode ='DCS101' AND ExamScore > 40;

Fig. 50: Output of the query to list out all courses that student with Reg. Number 99003 registered

for in the first semester of 2009/2010 session; as well as that student’s scores in the exams of those

courses.

When done, save the above query as Question6.

Lab Session 6, Task 4: Writing the SQL query to answer question number (vii) in the

requirements specs document: “List out all students whose exam scores in a given course fall

between a given score range (e.g. list all students who scored below 40 in DCS 209 or all

students who scored above 75 in DCS 201 or all students who scored between 50-60 in DCS

206).”

The above query lists out all students who scored above 40 in DCS 101 in the first

semester exams of 2009/2010 academic session. If done correctly, the query should

produce an output similar to the one shown in Fig. 51:

Page 59: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

59

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

SELECT StudentsTable.RegNumber, Surname, OtherNames, Gender,

ProgCode, LGAsTable.LgaName, StatesTable.StateName

FROM StatesTable INNER JOIN (LGAsTable INNER JOIN StudentsTable ON

LGAsTable.LgaID = StudentsTable.LgaID) ON StatesTable.StateID =

LGAsTable.StateID

WHERE StateName = 'KWARA';

Fig. 51: Output of the query to list out all students who scored above 40 in DCS 101 exams in first semester of 2009/2010 academic session.

When done, save the above query as Question7.

Lab Session 6, Task 5: Writing the SQL query to answer question number (viii) in the

requirements specs document: “List out all students who come from a particular LGA or

State of the country.”

The above query lists out all students who come from Kwara State. If done correctly, the

query should produce an output similar to the one shown in Fig. 52:

Page 60: Practical Laboratory Manual - Ahmadu Bello University · Practical Laboratory Manual For DCS 209: Introduction to Database Management (I) Diploma in Computer Science Year II, Semester

DSC209 Lab Manual: Introduction to Database Management (I) 2012

© IACC, ABU Zaria

PAGE

60

Downloaded from http://www.auwalgene.com/mystudents/lecturenotes

FREE, NOT FOR SALE!

Fig. 52: Output of the query to list out all students who are from Kwara State.

When done, save the above query as Question8.

THE END

Remember, you can download the complete project database file

for this lab manual from my website at

http://www.auwalgene.com/mystudents/lecturenotes/iacc-students-db.zip

Connect with me on Facebook at: http://www.facebook.com/auwalgene3

Drop me a comment or two on my website: http://www.auwalgene.com/comments

Tell me something via e-mail at: [email protected]

Send SMS text messages to my mobile phone at +234 (0) 8032126160

Thank you for reading, and happy data development!