Vous êtes sur la page 1sur 11

IS 4420 - Access Lab 1

Objectives:
A. Launch Microsoft Access and create a new database
B. Understand Microsoft Access environment
C. Create tables and insert data
D. Setup ODBC
E. Connect Oracle database usin ODBC
!. Use "uer# b# e$ample
A. Launch Microsoft Access and Create e! "atabase
%. Launch Microsoft Access usin the Start menu
&. Select #$an% Access database and clic' O& (Of course) in the future when #ou want to open an
e$istin database) #ou should choose open e$istin database*
+. Chane the file name to '(first.'db or an# other name #ou want and clic' Create
,. Conratulations- .ou/ve 0ust created #our first Access database when #ou see the window below1
%
#. )nderstand Microsoft Access *nviron'ent
%. E$plore the menu
&. E$plain 'e# ob0ects1 tables) "ueries) forms) reports) and macros
+. Understand Open view (to run an ob0ect* and Desin view (to desin an ob0ect*
C. Create +ab$es and Insert "ata
2e are oin to create a relation database accordin to the loical schema below. But to save time) we
will 0ust create the Department and Dept_Locations table and their relationship.

!3ame Minit L3ame SS3 BDate Address Se$ Salar# SuperSS3 Dep3o
!3ame Minit L3ame SS3 BDate Address Se$ Salar# SuperSS3
D3ame MrSS3 D3ame Dep3o MrSS3 MrSDate
Dep3o DLocation DLocation
43ame 43umber 4Location 43ame 43umber 4Location
ESS3 43o 5ours ESS3 43o 5ours
ESS3 Dependent63ame Se$ BDate 7elationship ESS3 Dependent63ame Se$ BDate 7elationship
Emplo#ee
Department
Dept6Locations
4ro0ect
2or's6On
Dependent
Dep3o
%. Double8clic' Create tab$e in "esi,n vie!
&. 9#pe "a'e as the !ield 3ame) and choose +e-t as the Data 9#pe
+. :n the ;eneral tab
a. Chane !ield Si<e to 1.
b. Select /es for 7e"uired (3ot 3ull*
&
c. Select /es 0o "u1$icates2 for :nde$ed (Uni"ue*
,. Do the similar for the other three attributes in the Department table accordin to the re"uirements
below.
Attribute "ata +(1e 3ri'ar( 4orei,n Constraint
Department 3ame =A7C5A7(%>* U3:?UE 3O9 3ULL
Department 3umber :39 3O9 3ULL
Manaer SS3 C5A7(@* 3O9 3ULL
Manae Start Date DA9E
>. 7iht8clic' the "e1o field and select 3ri'ar( &e(
A. Save the table as "e1art'ent and c$ose the table.
B. Create the dept6locations table similar accordin the re"uirements below.
Attribute "ata +(1e 3ri'ar( 4orei,n Constraint
Department 3umber :39
Department (Dep3o* O3
DELE9E CASCADE
3O9 3ULL
Department Location =A7C5A7(%>* 3O9 3ULL
C. Create relationship between the two tables.
a. Clic' 5e$ationshi1s under the 9ool menu
b. Select the two tables) clic' Add) and then C$ose
c. Select "e1o in the Dept6Locations table) hold the mouse left 'e#) dra, it onto the "e1o in
the Department table) and release the left 'e#.
d. Chec' *nforce 5eferentia$ Inte,rit(
e. Chec' Cascade "e$ete 5e$ated 5ecords
f. Clic' Create and #ou should be able to the window below
@. Double8clic' to open the Department table) enter the followin records1
+
+ab$e a'e: "e1art'ent
D3ame Dep3o MrSS3 MrDate
Manufacture % CCCAA>>>> %@8DU38B%
Administration & >,+&%ABC@ E,8DA38@@
%E. Close the Department table and enter the followin records for Dept6Locations table.
+ab$e a'e: "e1t6Locations
Dep3o DLocation
% 5ouston
% Chicao
& 3ew .or'
+ Salt La'e Cit#
9he s#stem won/t allow #ou to enter the last record) wh#F :nore the last record and carr# on. Close
m#first.dmb.
". Setu1 O"#C
.ou have 0ust learned how to create and populate tables in Microsoft Access. Alternativel#) #ou can
access Oracle database from Microsoft Access. But #ou will need to setup ODBC first.
%. Clic' Contro$ 3ane$ from the Start menu
&. Double clic' Ad'inistrative +oo$s (!or 2indows G4) #ou ma# need to switch from Cateor# =iew
to Classic =iew*.
+. Double clic' Data Sources and then clic' Add button
,. Scroll down and select Orac$e in Ora7o'e82
>. Clic' !inish and Enter the followin parameter values in the window below
Data Source 3ame1 is4420 (or an#thin #ou want*
Description1 "atabase 4unda'enta$s (or an#thin #ou want*
93S Service 3ame1 select IS4420
User :D1 (our user id (e$ample1 userC*
,
A. Clic' OH and then OH to e$it) and #ou have successfull# created an ODBC
*. Connect Orac$e "atabase )sin, O"#C
9he connection between a Microsoft Access and Oracle tables allows a lin'ae or reference to the data
stored in the Oracle tables. 9he data displa#ed in a Lin'ae 9able (in Access* are actuall# stored on
the Oracle database server. 9hus) all data manipulations (e..) data insertion and data deletion* in
Access will be reflected to the actual table on Oracle database server.
%. Launch Microsoft Access) and select I#$an% Access databaseI
&. 9hen) chane the !ile 3ame to '(odbc.'db (or an# other name #ou want*
+. 9o connect an Oracle table to Access) select I4i$eI) then I9et *-terna$ "ataI) and then clic' on
ILin% +ab$esI
,. A Lin' 9able dialoue screen will pop up (see the followin screenshot*. 9o indicate the table that
#ou would li'e to lin' is from ODBC) please select IO"#C "atabasesI in the I!iles of 9#peI
section) and clic' Lin%
>. Select the Machine "ata Source tab) and select #our data source (e$ample1 is4420*. :f the data
source if not available) refer to the J5ow to setup ODBCK instruction.
>
A. Upon clin' on JO&K for data source) an IOracle ODBC Driver ConnectI dialoue screen will
appear and as' #ou for I)ser a'eI and I3ass!ordI for accessin the Oracle database server.
4lease enter #our user name and password (when #ou lo on to S?L 4lus 2or'sheet* and then
clic' on O& to continue.
B. 4lease select the tables #ou want to lin') which are all the tables #ou created in Lab &. 7emember
to chec' the ISave 1ass!ordI. B# chec'in ISave passwordI) #ou are e$empted from re8enterin
#our password when attemptin to connect Oracle tables to Access databases in the future. Clic'
O&
A
C. .ou should be able to see the new tables with IEarth8li'eI icon in the 9ables section (see the
followin screenshot*. :f so) #ou have successfull# connected a table on an Oracle database server
to the Access database environment.
@. Double clic' on one table #ou have 0ust lin'ed and #ou should be able to see all the data (records*
stored in that table (as shown in followin screenshot*.
B
4. )se :uer( b( *-a'1$e
%. List department number) department name) and number of emplo#ees in each department) ordered
b# number of emplo#ees in each department. 2e have done this in Oracle S?L 4lus in Assinment >.
3ow let/s tr# it usin Microsoft Access ?BE.
&. Select :ueries under Ob0ects) and double clic' Create ;uer( in "esi,n vie!
+. Select the "e1art'ent and *'1$o(ee table) and clic' Add
,. Desin the "uer# as shown below. 3ote1 #ou can clic' the sin to show or not to show the
areate functionalit# +ota$
C
>. Clic' the < sin to run the "uer#) #ou should see the result below.
"*3O "AM* SSOfCount
% Manufacture %
& Administration %
+ 5ead"uarter %
, !inance +
> 7esearch ,
A. .ou can save this "uer# as counte'1$o(ee for future use) and #ou should see this "uer# under the
?ueries tab.
B. Select the S:L =ie! under the =iew menu) #ou will see the S?L command below1
SELEC9 USE7&&6DE4A79ME39.DE43O) USE7&&6DE4A79ME39.D3AME)
Count(USE7&&6EM4LO.EE.SS3* AS SS3OfCount
!7OM USE7&&6DE4A79ME39 :33E7 DO:3 USE7&&6EM4LO.EE O3
USE7&&6DE4A79ME39.DE43O L USE7&&6EM4LO.EE.DE43O
;7OU4 B. USE7&&6DE4A79ME39.DE43O) USE7&&6DE4A79ME39.D3AME
O7DE7 B. Count(USE7&&6EM4LO.EE.SS3*M
@
C. Let/s do another "uer#) list the name of emplo#ees who both lives (address* and wor's (department
location* in Salt La'e Cit#.
@. Select :ueries under Ob0ects) and double clic' Create ;uer( in "esi,n vie!
%%. Select the "e1t6Locations and *'1$o(ee table) and clic' Add.
%&. .ou will find unli'e the previous e$ample) there is no connection between those two tables.
%+. Dra the "*3O attribute in the Dept6locations table unto the "*3O in the Emplo#ee table to
create the 0oin) and then desin the "uer# as below
%E
%,. 5un the "uer# and here is the result1
4AM* LAM* A""5*SS "LOCA+IO
Dou ;ilbert %% S >@ E) Salt La'e Cit#) U9 Salt La'e Cit#
%>. ;o to the S:L =ie! to see the S?L code1
SELEC9 USE7&&6EM4LO.EE.!3AME) USE7&&6EM4LO.EE.L3AME)
USE7&&6EM4LO.EE.ADD7ESS) USE7&&6DE496LOCA9:O3S.DLOCA9:O3
!7OM USE7&&6DE496LOCA9:O3S :33E7 DO:3 USE7&&6EM4LO.EE O3
USE7&&6DE496LOCA9:O3S.DE43O L USE7&&6EM4LO.EE.DE43O
25E7E (((USE7&&6EM4LO.EE.ADD7ESS* Li'e INSaltNI* A3D
((USE7&&6DE496LOCA9:O3S.DLOCA9:O3* Li'e INSaltNI**M
%A. 4lease save and %ee1 a co1( of the '(odbc.'db file for ne$t lab.
%%

Vous aimerez peut-être aussi