Lesson 02_ TheTablesOfADatabase

download Lesson 02_ TheTablesOfADatabase

of 14

Transcript of Lesson 02_ TheTablesOfADatabase

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    1/14

    Introduction to Data Fields

    Database From Scratch

    In the previous lesson, we saw that you could create a database usingone of the available templates. This approach provides you with readilymade objects you can directly start using. Another technique consists of creating an empty database that has no built-in object. Starting adatabase from scratch allows you to create and add its different objectswhen necessary.

    The main advantage of this approach is that youwill exercise as much control as possible on yourdatabase because you will be creating all of yourobjects. The disadvantage is that you will missthat primary layout that the templates offer.Creating a database from scratch simply meansstarting from a blank database and adding thedifferent components. Of course, after learninghow to perform some changes, you will be ableto modify some aspects of a database, whethercreated from a template or started from scratch.

    To create a database from scratch, if you are justlaunching Microsoft Access, in the left section,you can click Featuring. Then, in the mainsection in the middle, click Blank Database, givea name in the File Name text box, and clickCreate.

    Ad s by Google

    Excel TemplatesSchema Excel

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    2/14

    Practical Learning: Creating a Blank Database

    Start Microsoft Access1.

    To start a new database, in the main section and under New Blank Database, click BlankDatabase

    2.

    In the right section, set the File Name to Clarksville Ice Cream13.

    Click Create to create the new database file4.

    Introduction to TablesImagine you create a list of people. The list can be started with names as follows: Bill, James,Hermine, and Khan. This type of list is considered one-dimensional because all of i ts items fit inone category. In order to create a more detailed list, you may want to include thesepeoples email addresses and probably other related information. If you include theseadditional pieces of information in the same category, the l ist may become confusing. Toarrange the list, you would divide it in categories. Here is an example:

    Name Email Address PhoneNumber Relationship

    Bill [email protected] FriendJames jamesemai l.com (102)399-2893

    Hermine(101)447-8384 Cousin

    Khan @Khan.com

    This type of display allows you to refer to a piece of information by its category. This is thebasis of a table. A table is a two-dimensional list of items so that the items are arranged bycategories. A complete or incomplete series of items that represent each category is called arecord. Therefore, a table can be represented as follows:

    In database development, a category is represented as a column. Sometimes it is also called afield. A record is represented as a row.

    Database Object and Fields

    A field is an object used to host, hold, or store a piece of information of a database. Beforesuch an object can perform its function, it must first be created. In the strict sense, the mostimportant or the most regularly used fields of a database are created on a table, but tables

    may not be the friendliest windows to present to a user for data entry. For this reason, fieldscan and should also be created on other windows.

    The process of making a field available depends on the type of object it will reside on andprobably how the field will be used. This leads to two categories of fields: those that canreceive or store information and those that can only present or display it. All fields of a table,especially in Microsoft Access, are created to store data. On the other hand, fields on almost allof the other objects (queries, forms, reports) can be made of combinations of already existingfields of a table, or they can be created independently of any existing or non-existing data.

    Table Layout

    The Table's Tab

    A table is presented as a rectangular window represented in the middle of the screen with atab. As an option, you can remove the tabs and let the tables display without them. To do this,you can click the Office Button and click Access Options. In the left frame, click CurrentDatabase and, in the right frame, in the Document Window Options section, click the TabbedDocuments radio button and remove the check mark on the Display Document Tabs check box:

    Custom FIBAperturesLow Cost Custom

    Aperture Strips with 3Day Deliverywww.Oregon-Physics.com

    #1 DatabaseSoftwareDevelop withUnlimited PowerDownload the FreeTrial herewww.4d.com/trial

    OOP with C++Training

    OOP Using C++Training CoursesQuickly Learn C++Programmingwww.e-learningcenter.com

    Excel forProcurementLearn how use MSExcel functions, likepivot tables, with thisclass!www.NextLevelPurchasing.c

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    3/14

    After making the selection, you can click OK. You will be asked to close and reopen thedatabase:

    Which you should do.

    On the left side of its top section, a table presents an icon . The table icon provides a menuyou can access when you right-click. The menu allows you to save or change the view of thetable.

    When a table displays with a tab, the extreme right section of the tab(s) shows a close button you can click to close the table.

    The Table System ButtonsIn Microsoft Office Access 2007, by default, a table in Datasheet View is represented with a tab,which prevents the user from moving it around. If you want, you can make the tables of adatabase appear as single documents. To do this, open the Access Options dialog box from theOffice Button and click. In the left frame, click Current Database. Under Document WindowOptions in the right frame, you can click the Overlapping Windows radio button before clickingOK:

    You will be asked to close and reopen the database.

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    4/14

    A Table as a Datasheet

    Although a table is primarily recognized as an arranged list of columns and rows, each columnand each row intersect to create a rectangular box called a cell:

    The cell is actually the object that holds data of a table. A cell holds only one piece of information. The database developer decides what type of information would go into a cell butthe user types that information. Based on its arrangement of cells, a table is said to display ina datasheet layout or simply a datasheet (because its view is made of cells).

    The Scroll Bars

    If you start entering data into a table and there are more records than the height of the tablecan display, the table would be equipped with a vertical scroll bar. The vertical scroll bar wouldallow you to move up and down on the datasheet. This is useful if/when a table has morerecords than can be displayed all at once, and this will happen regularly. In the same way, if atable contains one or more records than the width of the table can display, the table would beequipped with a horizontal scroll bar:

    The presence or absence of one or both scroll bars is automatically managed by the operatingsystem and you should not be concerned with the management of the scroll bars. At the sametime, if your users need to use a table, they know how to use a scroll bar.

    Table Navigation Buttons

    The lower left side of the table is made of four buttons used to navigate the table, one buttonused to create a new record, and a text box. Each button plays a specific role:

    Button Name Role

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    5/14

    First Record Allows moving to the first record of thetable

    Previous Record Allows you to move one record back (if there is one) from the current record

    Current RecordDisplays the number representing thecurrent record out of the total number of records

    Next Record Allows moving you one record ahead

    Last RecordAllows moving you to the last record of the table

    New (Blank) Record Used to enter a new record on the table

    Introduction to Table Creation

    Table Creation

    To have a table as part of your database, you must create it and you have various options. If you create a database using one of the local templates, it would provide you with a few tablesthat you can start using. To use a sample table, after starting a database, on the ribbon, youcan click Create. Then, in the Tables section, click Table Templates to see a list of sampletables:

    From the menu that appears, you can click one. This would open a new table for you. You canthen save it.

    Practical Learning: Using a Template Table

    Open the Rockville Technologies database created in the previous lesson1.

    On the Ribbon, click Create2.Click Table Templates3.

    Click Assets4.

    The Name of a Table

    Like everything that is part of a database, a table must have a name that can be used to referto that object throughout the database and in other files that can be linked to the table. Thereare two main ways you can specify the name of a table, either when you save it for the firsttime or if you decide to rename it.

    To save a table you have just created:

    You can click the Office Button and click Save

    You can right-click the Table_X (such as Table1) tab and click Save

    You can press Ctrl + S

    You can start closing the table. You would be prompted to save the change (if i ts structurehas been changed from the structure it had before it was opened)

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    6/14

    If a table has not been saved before, you will be asked to provide a name for the table. A tablecan have almost any name: Employees, 2&&4DG, Pestes, verTT#@tg, etc. Because you andyour users should be able to easily identify a table, there are suggestions you should followwhen naming it:

    The name of a table should reflect the kind of data it is holding

    You can name a table with a few words, with spaces

    You can use a prefix that identifies the table as such, a table. The name of a table would bepreceded with tbl. If the name includes one word, such as Musicians, you can give the tablea name like tblMusicians, another name would be tblStudentsIf the name of the table reflects a combination of words, such as Bank Accounts orStudents Academic Numbers, you should start each new word with an uppercase. Here areexamples: tblBankAccounts, tblStudentAcademicNumbers, tblMemberRegistrations.

    In our lessons, we will not use the convention of prefixing the name of adatabase object with three letters. For example, the names of tables will notstart with tbl. We came to this decision because most other databaseenvironments, including Microsoft SQL Server, do not suggest this rule.Although the lack of this rule may create some confusion, because you will endup having a table and a form with the same name, we will strive to explicitlystate what object type we are referring to. For example, we will avoid writing,"Open Employees" or "Open the Employees object". Instead, we will usuallystate, "Open the Employees table".

    Practical Learning:Saving a Table

    To save the table, right-click Table1 and click Save1.

    Set the name of the table to Corporate Items2.

    Click OK3.

    To close the table, click its Close button4.

    Table Management

    The Tables in the Navigation Pane

    Because the table is the primary object of a database, when you create a table and save it bygiving it a name, Microsoft Access creates a section in the Navigation Pane and name thatsection after the table. In the same way, you can have as many sections as the number of tables on the database. Here is an example:

    As we will see in the next lesson, some objects created that are based on the table would belisted under the table name in its category. Here is an example of two objects added to thesection of a table named Customers:

    Each section is expandable and collapsible. To expand a section, click the name of i ts section. tocollapse a section, click the blue header of its section.

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    7/14

    Once a table has been created and saved, it is represented in the Navigation Pane with an icon and a name.

    Opening a Table

    The most regular operations you will perform on a table require that you open it first. To opena table, first locate it in the Navigation Pane then:

    You can double-click the table

    You can right-click the table and click OpenAny of these actions causes the table to display in Datasheet View in the central area of thescreen. In the same way, you can open as many tables as necessary.

    Closing a Table

    After using a table, you can close it. Before closing a table, first select its tab. Then, to close atable:

    You can click the close button on the right side of the tabs

    You can press Ctrl + Shift + F4

    Selecting a Table

    In order to use a table, some operations require that you (or rather the user) first select(s) it:

    To select a table in the Navigation Pane, simply click it

    If you had opened many tables and they are displaying in the main area of the screen, toselect one, click its tab or its title bar

    If you have many tables displaying in the main area of the screen, you can press Ctrl + F6continuously to switch from one table to the next until the desired one displays

    Renaming a Table

    We saw that, when or after creating a table, you must save it to make it part of your database.When saving it for the first time, you must give it a name. If the name of a table is notappropriate, you can change it. To rename a table, in the Navigation Pane, you can right-click

    the name of the table and click Rename.

    Practical Learning: Renaming a Table

    In the Projects Navigation window, right-click the Corporate Items table and click Rename1.

    Type Employees Resources as the new name of the table2.

    Press Enter3.

    Deleting a Table

    If you have a table you don't need anymore, you can remove it from your database. Becauseyou cannot delete a table if it is opened, you must first close it.

    To remove a table from your database:

    In the Navigation Pane, right-click the table and click Delete

    In the Navigation Pane, click the table to select it. Then, on the ribbon, click Home. In theRecord section, click Delete

    In the Navigation Pane, click the table to select it and press Delete

    In each case, you will receive a warning to confirm what you want to do. It is important toknow that if you delete a table, because it is not a file, it does not go into the Recycle Bin: it islost, including its records. Therefore, before deleting a table, make sure you really want to getrid of it. When in doubt, do not delete it.

    Practical Learning: Deleting a Table

    In the Navigation Pane, right-click the Employees Resources table and click Delete1.Read the warning of the message box and click Yes2.

    Tables Columns in the Datasheet View

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    8/14

    Creating a Column

    Although we didn't mention it so far, a table does not exist without a column. Put it anotherway, a table must have a least one column in order to have meaning. This also means that, inorder to create a table, it must actually have at least one column. If you start a table inDatasheet View, Microsoft Access creates and gives it one default column. Once a table displaysin Datasheet View, you can start entering data into its cells. If you do this, whenever you enterdata under a column, that column receives an incremental name: the first column on the rightside of ID would be named Field1, the second would be Field2, and so on. These would beinsignificant and can even be confusing. Fortunately, you can give meaningful names to the

    columns of your table.

    Naming a Column

    A column can have almost any name: "Book Title", "DG$5@H", "This Is The Book Title","R8%%DW$4", etc. Some columns will have only tinny data, like a person's age, the numberof books in an office, a persons middle initial, etc. It may not be a good idea to give them aname that would take too much space. In the future, when you start programming, it would beeasier to handle field names that are composed of only one word, without space.

    To name a field, first figure out what the data in the category will be made of. If you areplanning to enter employees' salaries in a field, you can just call it Salary. If you want tospecify employees names by first name, middle name, and last name, you can use suchcolumn names and make them distinct. In this case, you could name the first column as firstname, the last name would be called last name. Although you can use one word names, somepeople might be confused. The suggestion is to distinguish wherever a new English (or thelanguage you are using to design your database) name starts in the field name, by using astarting uppercase. Instead of firstname or first name, you can use FirstName or First Name.Instead of fullname or full name, you can use FullName or Full Name.

    Before changing the name of a column:

    You can double-click i ts header

    You can right-click a column and click Rename Column

    When any cell under a column has focus, on the ribbon, you can first click Datasheet. Then,in the Fields & Columns section, click Rename Column.

    Any of these actions would put the name of the column into edit mode. You can then type thenew desired name or change the existing name.

    Practical Learning: Naming Datasheet Fields

    Re-open the Clarksville Ice Cream1 database created earlier1.

    To create a new table, on the ribbon, click Create2.

    Click Table3.

    Double-click A d d N e w F ie l d 4.

    When it is highlighted, type Order Date and press Enter

    5.

    As the caret in blinking in the next column header, type Order Time and press Enter6.

    As the caret in blinking in the next column header, type Container and press Tab

    7.

    Close the table8.

    When asked whether you want to save it, click Yes9.

    Type Customers Orders as the name of the table10.

    Click OK11.

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    9/14

    Using a Template Field

    If you create a table using one of the templates, it would have ready-made fields. If you createa table from scratch, it may lack some fields. Fortunately, Microsoft Access provides manypre-configured fields you can add to your table, whether you create the table based on atemplate or from scratch. These ready-made sample columns are referred to as a FieldTemplates.

    Before using a field template, from the ribbon, click Create and click New Table. This wouldstart a new table and the ribbon would switch to the Datasheet tab. In the Fields & Columns

    section, click New Field. This would display the Field Templates window:

    By default, the Field Templates window is positioned on the right side of the screen. This is adockable window: you can move it to the left or place it somewhere else on the screen.

    The items in the Field Templates window are organized in categories identified with a labelednode, such as Basic Fields, Assets, or Contacts. Each node displays a - button. This - buttonindicates that the node is expanded. To collapse a node, you can click its - button, whichbecomes a + button. To expand a node, you can click its + button. Here is an example wherethe Assets, the Contacts, and the Issues nodes are collapsed while the Events and the Projectsnodes are expanded:

    To use a field from the Field Templates window:

    You can double-click the field

    You can click and drag the field from the Field Templates and drop it on the table to the leftof A d d N e w F i e l d :

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    10/14

    Practical Learning: Using Field Templates

    The Clarksville Ice Cream1 database should still be opened.To start a new table, on the ribbon, click Create

    1.

    Click Table2.

    In the Fields & Columns section of the Datasheet tab, click New Field3.

    Under the Field Templates, expand the Assets node if necessary.In the Assets section, double-click Manufacturer , Model , Acquired Date , and PurchasePrice

    4.

    Expand the Contacts node if necessary.Under Contacts, drag Company and drop it between ID and Manufacturer5.

    Right-click Table1 and click Save6.

    Set the name to Company Assets7.

    Click OK8.

    Click its Close button9.

    Columns Maintenance in the Datasheet View

    Importing a Table and its Columns

    Although a column completely depends on a table, both objects are closely related when itcomes to their maintenance. In other words, the maintenance performed on one object candirectly affect the other. For example, you can import a table from a text file or from anotherapplication. A table cannot exist without at least one column.

    Selecting a Column

    Some operations will require that you select a column but it depends on the operation. In somecases, when any cell under a column has focus (for example if the caret is blinking in a cell of acolumn), the column is considered to be selected. Otherwise:

    To select one column, position the mouse on i ts name until the cursor points down andthen click

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    f 14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    11/14

    To select columns in a range, click and hold your mouse on one of them, then drag to theleft or to the r ight to cover the other desired column or columns. When all desired columnsare highlighted, release the mouse

    To select a range of columns, click one column that will be at one end, press and hold Shift,then click the column that will be at the other end, and release Shift

    Changing the Width of a Column

    If you create a table using one of the Table Templates or if you get a table from a DatabaseTemplate, the columns of the tables are wide enough to show their names. If you create a tablefrom scratch in the Datasheet View, Microsoft Access assigns it a default width. That width canappear to be too narrow or too wide. For example, when data exceeds the regular width of acolumn, part of the information would be hidden. If a particular column contains data that youwant to display at all times, you can enlarge the column. On the other hand, if a columndisplays tinny pieces of information, you can narrow the column to let it just fit the data asdesired. There are various techniques you can follow to widen or narrow a column.

    To change the width of a column:

    you can position the mouse on the right border of a column header. The mouse pointerwould change into a horizontal double arrow crossed by a vertical line:

    If you double-click, the column would be resized to the widest value of the column,provided the widest value is wider than the column header. If the widest value is narrower

    than the column header, the column width would be widened enough to display the nameof the column.

    You can click the column's right border and drag in the desired direction, left or r ight untilyou get the desired width

    You can right-click a column's name and click Column Width... This would open the ColumnWidth dialog box where you can type the desired value and click OK

    Moving a Column

    If you find out that a particular column is misplaced in a table, you can change its position.

    To move a column in Datasheet View, first select it, click and hold your mouse on i t. Then, startdragging left or right in the desired direction. While your mouse is moving, a thick vertical line

    will guide you. Once the vertical line is positioned to the desired location, release the mouse:

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    f 14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    12/14

    To move a group of columns, first select them as we reviewed earlier, click and hold the mouseon one of the selected columns, start dragging left or right in the desired direction until thethick vertical guiding line is positioned in the desired location, then release the mouse:

    Inserting a Column

    Inserting a column consists of adding one between two existing fields. There are various waysyou can do this:

    To insert a column using the ribbon, first click a cell under the column that will succeed it.

    Then, in the Fields & Columns section of the Datasheet tab, click the Insert button

    To insert a column from the table, right-click the column that will succeed it and click InsertColumn

    To insert a field from the Field Templates, click and drag it from the Field Templates anddrop it to the left of the column that will succeed it

    Practical Learning: Inserting a Column

    The Clarksville Ice Cream1 database should still be opened.In the Navigation Pane, double-click the Customers Orders: Table to open the table

    1.

    To add a new field, right-click the Order Date column header and click Insert Column2.

    Click the empty cell under Container3.

    On the ribbon, click Datasheet if necessary.

    In the Fields & Columns section, click the Insert button

    4.

    Renaming a Column

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    f 14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    13/14

    We saw various techniques of naming a column. You can use the same approach to change thename of a column. To put the name of a column into edit mode and then change i t:

    You can double-click i ts name on the header

    You can right-click the column's name and click Rename Column

    When any cell under the column has focus, on the ribbon, click Datasheet, in the Fields &

    Columns section, click the Rename button

    Practical Learning: Renaming a Column

    The Clarksville Ice Cream1 database should still be opened.Right-click the Field1 column header and click Rename Column

    1.

    Type Clerk and press Enter2.

    Click the empty cell under Field23.

    In the Fields & Columns section of the ribbon, click the Rename button4.

    Type Flavor and press Enter5.

    Close the table6.

    Hiding and Revealing a Hidden Column

    If a table contains many columns and at one time you think you don't need all of them, youcan hide some. To hide a column, you can drag the right border of its column headercompletely to its left border as we saw earlier to change the width of a column; when thevertical guiding line reaches the left border, release the mouse: the column would be hiddenfrom the table:

    To hide one or a group of columns, you can right-click and click Hide Column. You can alsoright-click any column and click Unhide Column. This would open the Unhide Columns dialogbox. Here is an example:

    To hide a column, clear its check box.

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht

    f 14 31/08/2012 17:14

  • 8/13/2019 Lesson 02_ TheTablesOfADatabase

    14/14

    To reveal a column or a group of columns previously hidden, right-click any column header onthe table and click Unhide Column. In the Unhide Columns dialog box, put a check mark oneach column you want to show.

    Deleting a Column

    If you have an undesirable column in a table, you can delete it. It is important to keep in mindthat if you delete a column, it also goes with any information under it.

    To remove a column from a table:

    You can right-click the column's name and click Delete Column

    You can select the column (or a group of columns), right-click anywhere in the table andclick Delete Column

    You can select a column (or a group of columns). Then, in the ribbon, click Datasheet. In

    the Fields & Columns section, click the Delete button

    Any of these actions would present you a warning to confirm whether you still want to deletethe column(s) or you want to change your mind. If you still want to remove the column(s),click Yes.

    Lesson Summary

    MCAS: Using Microsoft Office Access 2007 Topics

    C1 Create databasesC2 Create tablesC3 Modify tablesE2 Navigate among records

    Exercises

    Yugo National Bank

    Create a blank database and name it Yugo National Bank11.

    Double-click Add New Field and type AccountType2.

    Add one more column named Description 3.

    Change ID to AccountTypeID4.

    Save the table as AccountTypes5.

    Watts A loan

    Create a blank database and name it Watts A Loan11.

    After the default ID column, create the following additional columns: FirstName ,MiddleName , LastName , Address , City , State , ZIPCode , Country , HomePhone ,WorkPhone , EmailAddress , and Notes

    2.

    Rename the ID column as CustomerID ,3.Save the table as Customers4.

    Previous Copyright 2008-2012 FunctionX Next

    Create Excel on system iNative Excel .xls or .xlsx No PC needed. Add styling/cond fmts

    www.ariadnesoftware.co.uk

    rosoft Access Tutorial - Lesson 2: The Tables of a Database http://www.functionx.com/access2007/Lesson02.ht