Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

11
Ken Goldberg Database Lab Notes Lab 2: MS ACCESS Tables Summary Introduction to Tables and How to Build a New Database Creating Tables in Datasheet View and Design View Working with Data on Sorting and Filtering 1. Introduction Creating a New atabase First, open S !cc ess "##$% To build a new databas e, choose New !lan " at aba se. B& selecting New !lan" atabase, a panel will show up on the right, which allows us to create a blank database b& entering the database na'e and choosing the location where on the co'puter we want to create the new database% We can also create a new database (ro' other database te'plate% For this session, we will (ocus on creating a database (ro' a blank one, so click New !lan" atabase  !lan" atabase% 1

Transcript of Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

Page 1: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 1/11

Ken Goldberg Database Lab Notes

Lab 2: MS ACCESS Tables

Summary• Introduction to Tables and How to Build a New Database

• Creating Tables in Datasheet View and Design View

• Working with Data on Sorting and Filtering

1. Introduction

Creating a New atabaseFirst, open S !ccess "##$% To build a new database, choose New !lan" atabase. B&selecting New !lan" atabase, a panel will show up on the right, which allows us to create ablank database b& entering the database na'e and choosing the location where on the co'puter

we want to create the new database% We can also create a new database (ro' other databasete'plate% For this session, we will (ocus on creating a database (ro' a blank one, so click New

!lan" atabase  !lan" atabase%

1

Page 2: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 2/11

Ken Goldberg Database Lab Notes

#ig. 1: Creating a New atabase)nce &ou created a blank database and t&pe the database na'e, &ou can create the (ollowing si*ob+ects as shown in Fig% ", the& are brie(l& described as (ollows,• Tables a collection o( data about a speci(ic topic, such as products or suppliers%

• $ueries a co''and (or -iewing or anal&.ing data in di((erent wa&s or a result o( theco''and%

• #orms a (riendl& inter(ace to add a new record

• %e&orts an ob+ect that present data in a organi.ed wa& according to &our speci(ication%/*a'ples are telephone bills, sales su''ar& etc%

• Macros a set o( one or 'ore actions that each per(or's a particular operation, such as

opening a (or' or printing a report% acros can help &ou to auto'ate co''on tasks% Fore*a'ple, &ou can run a 'acro that prints a report when a user clicks a co''and button%

• Module a collection o( Visual Basic (or !pplications declarations and procedures that arestored together as a unit%

#ig. 2 New atabase atabase1.accdb

2

Page 3: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 3/11

Ken Goldberg Database Lab Notes

2. Creating a Table:There are three wa&s to create a table0

• 1se Datasheet View, i%e% enter data directl&

• 1se Design View

• 1se a Table Te'plate

2.1 Create a Table in atas'eet (iewTo create a blank 2e'pt&3 table in datasheet -iew, on the %ibbon &ou can0• Click Create Table in Fig% 4%5ou are then gi-en a Datasheet View with colu'n headings ID and !dd New Field across the topo( the datasheet as shown in Fig% 6% 5ou can enter data directl& into it% !(ter entering data and hitthe /nter ke&, the colu'n heading !dd New Field auto'aticall& changes to Field7 and the ne*tcolu'n8s heading beco'es !dd New Field% !t the sa'e ti'e, an ID nu'ber will be assigned tothat row% When &ou sa-e the new datasheet, icroso(t !ccess will anal&.e &our data andauto'aticall& assign the appropriate data t&pe and (or'at (or each (ield% Because the na'es o(each (ield are not descripti-e, &ou 'a& want to rena'e the (ields%

#ig. ) %ibbon *or Creating New Table

%enaming #ields:7% 9lace the cursor o-er the colu'n heading &ou want to rena'e and double click% The colu'n

heading will appear highlighted and the cursor will be blinking 2&ou are now in edit 'ode3"% T&pe the na'e &ou want to use and then press the /nter ke&%

4% :epeat the (irst two steps (or the second colu'n, and so on%

#ig. +: Creating a Table in atas'eet (iew ,%enaming #ields-

 !s the colu'n corresponds to the (ield, the row corresponds to the record% Now we are read& toadd the in(or'ation% Sa& that, i( we are doing a database o( a co'pan&, the (irst table we 'a&

3

Page 4: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 4/11

Ken Goldberg Database Lab Notes

ha-e is Employee% !nd the (ields o( /'plo&ee 'a& contain SSN, ;astNa'e, FirstNa'e, and soon% 9lease re(er to Fig% < (or the e*a'ple /'plo&ee table%

#ig. : atas'eet (iew ,Em&loyee Table-

Summari/ing atas'eet (iew

2.2 Create a Table in esign (iewIn Design View &ou can add (ields, de(ine how each (ield appears or handles data, and create apri'ar& ke&% To create a blank 2e'pt&3 table in design -iew, &ou can0• Click Create Table esign in Fig% 4% 5ou are then gi-en a Design View as shown in Fig% =%

4

Page 5: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 5/11

Ken Goldberg Database Lab Notes

#ig. 0 esign (iewIn this -iew, we can speci(& detailed properties (or each (ield% This includes the length and t&pe o(in(or'ation used in the (ield% But i( we were to enter data into the table, we 'ust use atas'eet(iew or #orms% The design -iew (or the e*a'ple /'plo&ee table 'entioned be(ore will look likeFig% $%

#ig. esign (iew ,Em&loyee Table-

5

Page 6: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 6/11

Ken Goldberg Database Lab Notes

There are three colu'ns on the top portion o( the window% The #ield Name is the na'e o( the(ields% For e*a'ple, SSN, FirstNa'e, ;astNa'e are proper (ield na'es (or the /'plo&ee table%The na'e (or a (ield 'ust (ollow S !ccess obect3naming rules1% The ata Ty&e is like thedo'ain o( an attribute% It pro-ides a list o( data t&pes that we can choose (ro', including Te*t,e'o, Nu'ber, Date, and so on% The escri&tion colu'n allows us to describe the (ield and it isoptional. It is always good practice to be descriptive in your comments.  This allows new users toeasil& understand the speci(ications and 'eaning o( &our (ields% Table " su''ari.es all datat&pes a-ailable in S !ccess%

5ou can set up properties o( (ields in the #ield 4ro&erties window at the botto' hal( pane% Table7 describes all properties a-ailable (or setup%

Be(ore we sa-e the table and >uit, we need to speci(& the &rimary "ey% In our /'plo&ee table,SSN will be good (or pri'ar& ke&% To de(ine SSN as the pri'ar& ke&, click the #ield Selector asshown in Fig% $ (or the SSN (ield% Field Selector is the gra& bar on the le(t side o( the TableDesign grid b& each (ield% When we click here, the whole row appears highlighted% Then click'enu Edit 4rimary 5ey or click the 9ri'ar& ?e& button 2i%e% the ke& s&'bol, shown in Fig% $3on the toolbar in design -iew, a ke& s&'bol will appear on the Field Selector% Sa-e the table as/'plo&ee% Now we ha-e created one table%"

Table 1 #ield 4ro&erties in esign (iew

1 Object-naming rules are a set of specific rules for naming icrosoft !ccess objects" #n icrosoft !ccess$

names can be up to %4 c&aracters long and can include an' combination of letters$ numbers$ spaces$ andspecial c&aracters e(cept a period )"*$ an e(clamation point )+*$ an accent gra,e )*$ and brac.ets )/ 0*" Note

t&at 'ou also cant use leading spaces or control c&aracters )!## ,alues to 31*" or information on

6isual 7asic naming con,entions$ searc& t&e 8elp inde( for 9naming con,entions"9

:ips

; !,oid including spaces in object names if 'oull fre<uentl' refer to t&e objects in e(pressions or 6isual

7asic code"

; !,oid using e(tremel' long names because t&e' are difficult to remember and refer to"

%

Page 7: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 7/11

Ken Goldberg Database Lab Notes

Table 2 ata Ty&es in MS Access

T

=

Page 8: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 8/11

Ken Goldberg Database Lab Notes

Summari/ing esign (iew2

2.) Create a Table !ased on a Table Tem&lateTo create a Contacts, Tasks, Issues, /-ents or !ssets table, &ou 'ight want to start with thetable te'plates (or these sub+ects that co'e with )((ice !ccess "##$% To choose a te'plate (or&our table (ro' the abo-e prede(ined te'plates &ou can0

• Click Create Table Tem&lates in Fig% 4,

• Select one o( the a-ailable te'plates (ro' the dropdown list%

). 6or"ing wit' ataIn this section, we will learn how to work with e*isting data% The sa'ple database (ile used here is@Northwind "##$%accdb@% It is a sa'ple database co'es with icroso(t !ccess% 5ou can (ind it in

b&0• )pen S !ccessA click Sam&le under the categor& listed in the le(t task pane on the

7etting Started wit' 8**ice Access pageA then click on the Nort'wind 299 icon, enterthe na'e and location on the right task pane and click the Download button%

or • o to director& C:4rogram #ilesMicroso*t 8**iceTem&lates19))Access and

double click Nort'wind.accdb%Choose 8bect Ty&e on the Na;igation 4ane a(ter Northwind "##$%accdb is launched, )pen@8rders@ under @Tables@%

).1 SortingIn the atas'eet (iew, we can sort the records in ascending or descending orders% To sort asingle colu'n, click an&where in the colu'n desired% Si'pl& click either the Sort !scending

button or Sort Descending button on the %ibbon% We can also click the arrow on theright o( the desired colu'n heading and choose Sort !scending or Sort Descending (ro' thepopup window%

2 >ou can set combination of more t&an t?o attributes as a primar' .e'" :o do so$ first &ig&lig&t attributes

'ou ?is& to set as primar' .e'$ and clic. @rimar' Ke' button in design ,ie?"

A

Page 9: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 9/11

Ken Goldberg Database Lab Notes

I( we want to sort multiple columns, we need to do a little 'ore work% The two colu'ns we want tosort b& 'ust be ad+acent to each otherA the one that we want to sort b& (irst 'ust be to the le(t o(the other% ;ets work with @8rders@ table in Nort'wind atabase% Now we will tr& sorting b& S'i&&ed ate< then b& <8rder ate, we 'ust (irst 'o-e Shipped Date colu'n to the le(t o()rder Date colu'n% Here are the steps,

7% Highlight the <S'i&&ed ate colu'n b& clicking the <S'i&&ed ate colu'n heading%"% ;et go o( the 'ouse button and then press it again, holding it this ti'e%4% Now drag the <S'i&&ed ate< colu'n o-er the <%e=uired ate< colu'n% When we get

 +ust to the le(t o( the <8rder ate<, let go o( the 'ouse button% Then <S'i&&ed ate< and<8rder ate< should sit side b& side now%

6% Click the 'ouse button on the <S'i&&ed ate< header, highlighting the colu'n% Holdingthe 'ouse button down, drag it o-er the <8rder ate< colu'n so that both the <S'i&&edate< and <8rder ate< colu'ns appear highlighted%

<% Click on Sort Ascending% The sorted table is shown in Fig% %

#ig. >: Nort'wind atabase: Sort %esult

).2 #iltersB& using Filter by Selection, &ou tell !ccess that &ou want to see onl& certain records, based onthe -alue in the (ield in which the cursor currentl& resides% For e*a'ple, sa& that we want to seethose orders shipped -ia Shipping Co'pan& B% To do this,7% In the <S'i& (ia< colu'n, click a (ield that has ?S'i&&ing Com&any !@ in this (ield%"% Click the right button o( 'ouse and select E=uals ?S'i&&ing Com&any !?% )r, &ou 'a&

click Selections button in the :ibbon and select E=uals  ?S'i&&ing Com&any !?% )nl&those records that were shipped -ia Shipping Co'pan& B appear%

4% Click the right button again and select @Clear *ilter *rom S'i& (ia@ button to re'o-e the (ilter%

B

Page 10: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 10/11

Ken Goldberg Database Lab Notes

With #ilter by Selection, &ou were (iltering records based on a (ield &ou selected in thedatasheet, and then selected another (ield in the subset to narrow it (urther% When using #ilter by#orm, !ccess takes &ou to a di((erent screen to speci(& the criteria &ou want to (ilter with% 1sing#ilter by #orm, although 'ore co'plicated, allows &ou to be 'ore speci(ic and (ilter &our databased on a co'bination o( selected -alues (ro' 'ultiple (ields% To do this,1" )n the %ibbon click on Ad;anced #ilter 8&tions #ilter by #orm

"% The datasheet will suddenl& look as i( &ou deleted all the records% :e(er to Fig% E (or e*a'ple%Now &ou can pick the (ields &ou want to (ilter and displa& &our in(or'ation%4% Click S'i& (ia (ield to see the dropdown list% 5ou can use , G, , G, and to speci(& &our

criteria%6% Finall&, on the :ibbon click on Toggle #ilter to see the result%

#ig. @ #ilter by #orm

In the end, we will see how to use AN and 8% criterion in a (ilter% The AN operator allows &outo (ilter records based on two or 'ore criteria% When &ou appl& a (ilter using the !ND operator,onl& those records that 'eet both 2or all3 criteria appear% To show how to use the !ND operator,we will choose all orders shipped be(ore #"7""##= AN shipped -ia Shipping Co'pan& B% Todo this,1" )n the %ibbon, click Ad;anced #ilter 8&tions#ilter by #orm to return to the #ilter by

#orm screen% The screen should be blank%"% Click S'i&&ed ate, select 2122990 and add ?B? be(ore the date so that it looks like?B2122990?%

4% Click S'i& (ia and select ?S'i&&ing Com&any !@ 2without >uotation 'ark3%6% Click the Toggle #ilter button on the %ibbon% Now those orders shipped be(ore #"7""##=

AN shipped -ia Shipping Co'pan& B will appear% The resulting table contains " records%9lease check &our answer%

To show all the orders which is either shipped be(ore #"7""##= 8% shipped -ia ShippingCo'pan& B, &ou can %1" )n the %ibbonD click Ad;anced #ilter 8&tionsClear All #ilters%2" )n the %ibbon, click Ad;anced #ilter 8&tions#ilter by #orm to return to the #ilter by

#orm screen% The screen should be blank%

4% Click S'i&&ed ate and select @2102990@ and add ?B? be(ore the date%6% Click the 8r tab at the botto' o( the #ilter by #orm screen%<% Click S'i& (ia and select ?S'i&&ing Com&any !? 2without >uotation 'ark3%=% 9ress Toggle #ilter   on the %ibbon% Now those orders that are either shipped be(ore

#"7""##= or shipped -ia Shipping Co'pan& B will appear% The resulting table contains 4=records%

JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJC)N:!T1;!TI)NS K 5ou ha-e learned the basics o( creating and 'anipulating tables o( dataJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ

$ui/ 2

1

Page 11: Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

7/27/2019 Lab2 MSA Tableshahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!hahah!

http://slidepdf.com/reader/full/lab2-msa-tableshahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahahhahah 11/11

Ken Goldberg Database Lab Notes

2Due at start o( ne*t class3

)pen the Northwind "##$ sa'ple database and answer the (ollowing >uestions0

7% In the L9roducts8 table, what is the data t&pe (or the last colu'nM Create a si'pletable LStudents8 with one (ield SSN, and one (ield Image with the sa'e data t&pe as

the last colu'n in table 9roducts% 9opulate the table with so'e data and list steps onhow &ou insert i'age (iles into this table%

"% In so'e o( the tables, the 7st colu'n on the le(t shows a sign% Click on it anddescribe shortl& what happens%

4% In the Design View o( a table, right click under the (ield na'e colu'n% Tr& to click onthe Build option and describe what happens%

6% B& using FI;T/: option in the T!B;/0 )rders, how 'an& orders were shipped

ona(ter Oune"##=M !nd where were the& shipped (ro' 2;ist ship cit& onl&3M

<% In the sa'e table, how 'an& orders were shipped with Shipping Fee between P"#and PE#M

=% In the sa'e table, using FI;T/:S):T, a'ong the orders that were shipped on the !pril<"##=, which one is the 'ost e*pensi-e one 2in ter's o( 'erchandise costs,N)T (reight3M Which one is the cheapest oneM 29lease gi-e )rderID and cost onl&3

11