You are on page 1of 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 !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 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%

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( the co''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% For e*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 are stored together as a unit%

#ig. 2 New

atabase

atabase1.accdb

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 (iew


To 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 top o( the datasheet as shown in Fig% 6% 5ou can enter data directl& into it% !(ter entering data and hit the /nter ke&, the colu'n heading , !dd New Field auto'aticall& changes to Field7 and the ne*t colu'n8s heading beco'es !dd New Field% !t the sa'e ti'e, an ID nu'ber will be assigned to that row% When &ou sa-e the new datasheet, icroso(t !ccess will anal&.e &our data and auto'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& to add the in(or'ation% Sa& that, i( we are doing a database o( a co'pan&, the (irst table we 'a&

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

#ig. .: atas'eet (iew ,Em&loyee TableSummari/ing atas'eet (iew

2.2 Create a Table in esign (iew


In Design View &ou can add (ields, de(ine how each (ield appears or handles data, and create a pri'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% =%

Ken Goldberg Database Lab Notes

#ig. 0 esign (iew In 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 like Fig% $%

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

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 ob2ect3naming rules1% The ata Ty&e is like the do'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 is optional. It is always good practice to be descriptive in your comments. This allows new users to easil& understand the speci(ications and 'eaning o( &our (ields% Table " su''ari.es all data t&pes a-ailable in S !ccess% 5ou can set up properties o( (ields in the #ield 4ro&erties window at the botto' hal( pane% Table 7 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 as shown in Fig% $ (or the SSN (ield% Field Selector is the gra& bar on the le(t side o( the Table Design 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% $3 on 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

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$ and special c&aracters e(cept a period )"*$ an e(clamation point )+*$ an accent gra,e )-*$ and brac.ets )/ 0*" Note t&at 'ou also can1t use leading spaces or control c&aracters )!23## ,alues 4 to 31*" 5or 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 'ou1ll 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"

Ken Goldberg Database Lab Notes

Table 2 ata Ty&es in MS Access T

Ken Goldberg Database Lab Notes Summari/ing esign (iew2

2.) Create a Table !ased on a Table Tem&late


To create a Contacts, Tasks, Issues, /-ents or !ssets table, &ou 'ight want to start with the table 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' ata


In 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 2991 icon, enter the na'e and location on the right task pane and click the Download button% or Bo to director& C::4rogram #iles:Microso*t 8**ice:Tem&lates:19)):Access: and double click Nort'wind.accdb% Choose 8b2ect Ty&e on the Na;igation 4ane a(ter Northwind "##$%accdb is launched, )pen @8rders@ under @Tables@%

).1 Sorting
In the atas'eet (iew, we can sort the records in ascending or descending orders% To sort a single 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 the right o( the desired colu'n heading and choose Sort !scending or Sort Descending (ro' the popup window%

>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?"

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 to sort 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% ;etCs work with @ 8rders@ table in Nort'wind atabase% Now we will tr& sorting b& C S'i&&ed ate< then b& <8rder ateC, we 'ust (irst 'o-e CShipped DateC colu'n to the le(t o( C)rder DateC colu'n% Here are the steps, 7% Highlight the <S'i&&ed ateC colu'n b& clicking the <S'i&&ed ateC 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% Holding the 'ouse button down, drag it o-er the <8rder ate< colu'n so that both the <S'i&&ed ate< and <8rder ate< colu'ns appear highlighted% <% Click on Sort Ascending% The sorted table is shown in Fig% D%

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

).2 #ilters
B& using Filter by Selection, &ou tell !ccess that &ou want to see onl& certain records, based on the -alue in the (ield in which the cursor currentl& resides% For e*a'ple, sa& that we want to see those 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%

Ken Goldberg Database Lab Notes With #ilter by Selection, &ou were (iltering records based on a (ield &ou selected in the datasheet, 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 data based 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 drop,down list% 5ou can use F, G, H, GF, and HF 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 &ou to (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 #"I7"I"##= AN shipped -ia Shipping Co'pan& B% To do 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 2A12A2990 and add ?B? be(ore the date so that it looks like ?BC2A12A2990C?% 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 #"I7"I"##= 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 #"I7"I"##= 8% shipped -ia Shipping Co'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 @2A10A2990@ 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 #"I7"I"##= or shipped -ia Shipping Co'pan& B will appear% The resulting table contains 4= records% JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ C)NB:!T1;!TI)NS K 5ou ha-e learned the basics o( creating and 'anipulating tables o( data JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ

$ui/ 2 14

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'ple table 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 on how &ou insert i'age (iles into this table%

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

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

6% B& using FI;T/: option in the T!B;/0 )rders, how 'an& orders were shipped onIa(ter Oune,D,"##=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/:IS):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

You might also like