Defining Table Relationships

732 views

Published on

Building a Database And Defining Relationships with Microsoft Access 2010

Published in: Software
  • Be the first to comment

  • Be the first to like this

Defining Table Relationships

  1. 1. Building a Database and Defining Table RelationshipsMicrosoft Access 2010 ®
  2. 2. Objectives XP • Learn the guidelines for designing databases and setting field properties • Modify the format of a field in Datasheet view • Create a table in Design view • Define fields and specify a table’s primary key • Modify the structure of a tableNew Perspectives on Microsoft Access 2010 2
  3. 3. Objectives XP • Import data from an Excel worksheet • Create a table by importing an existing table structure • Add fields to a table with the Data Type gallery • Delete, rename, and move fields • Add data to a table by importing a text file • Define a relationship between two tablesNew Perspectives on Microsoft Access 2010 3
  4. 4. Table Window in Design View XPNew Perspectives on Microsoft Access 2010 4
  5. 5. Guidelines for Designing Databases XP • Identify all the fields needed to produce the required information • Organize each piece of data into its smallest useful part • Group related fields into tables • Determine each table’s primary key • Include a common field in related tables • Avoid data redundancy • Determine the properties of each fieldNew Perspectives on Microsoft Access 2010 5
  6. 6. Guidelines for Setting Field Properties XP • You must name each field, table, and other object • Choose an appropriate data type Database Table Data Types: The newest version of Microsoft Access marks the introduction of a new data types for your fields when creating tables. In addition to these new formats there are also changes to the previous formats that were available in earlier versions of Microsoft Access. Data Types Microsoft Access 2007 Data Types Data Type Description An AutoNumber field creates unique values automatically when Access creates a AutoNumber new record. The AutoNumber field is primarily used for Primary Keys in Access. A Text field can contain values that are text, numeric or a combination of both. Text A text field can contain a maximum length of 255 characters. A much larger version of the text field, allowing storage of up to 2 GB of data. A Memo new feature of the Microsoft Access Memo field is that it now supports rich text formatting. Number The Number field can store numeric values up to 16 bytes of data. The Date/Time field allows storage of date and time information. The date/time Date/Time field now also includes the Auto Calendar feature. The Currency data type stores values in a monetary format. This can be used Currency with financial data as 8-byte numbers with precision to four decimal places. Yes/No Boolean data storage of true/false values. The OLE Object field stores images, documents, graphs etc. from Office and OLE Object Windows based programs. The maximum data size is 2 GB, although this will slow down a database. The Hyperlink field type is used to store web addresses. This has a maximum Hyperlink size limit of 1 GB of data. The Attachment field type is used to store images, spreadsheet files, documents, charts and other types of supported files to the records in your Attachment database. This is a new feature that has been introduced with Microsoft Access 2007New Perspectives on Microsoft Access 2010 6
  7. 7. Guidelines for Setting Field Properties XP • The Field Size property defines a field value’s maximum storage size for Text, Number, and AutoNumber fields only Byte Integer Long Integer Single Double Replication ID DecimalNew Perspectives on Microsoft Access 2010 7
  8. 8. Changing the Format of a Field in XP Datasheet ViewNew Perspectives on Microsoft Access 2010 8
  9. 9. Creating a Table in Design View XP • Creating a table in Design view involves entering the field names and defining the properties for the fields, specifying the primary key, and saving the table structureNew Perspectives on Microsoft Access 2010 9
  10. 10. Defining a Field in Design View XP • In the Field Name box, type the name for the field, and then press the Tab key • Accept the default Text data type, or click the arrow and select a different data type for the field. Press the Tab key • Enter an optional description for the field, if necessary • Use the Field Properties pane to type or select other field properties, as appropriateNew Perspectives on Microsoft Access 2010 10
  11. 11. Defining a Field in Design View XPNew Perspectives on Microsoft Access 2010 11
  12. 12. Specifying the Primary Key in Design View XP • Display the table in Design view • Click in the row for the field you’ve chosen to be the primary key to make it the active field. If the primary key will consist of two or more fields, click the row selector for the first field, press and hold down the Ctrl key, and then click the row selector for each additional primary key field • In the Tools group on the Design tab, click the Primary Key buttonNew Perspectives on Microsoft Access 2010 12
  13. 13. Specifying the Primary Key in Design View XPNew Perspectives on Microsoft Access 2010 13
  14. 14. Moving a Field XP • To move a field, you use the mouse to drag it to a new location in the Table window in the Table Design gridNew Perspectives on Microsoft Access 2010 14
  15. 15. Adding a Field Between XP Two Existing Fields • In the Table window in Design view, select the row below where you want the new field to be inserted • In the Tools group on the Design tab, click the Insert Rows button • Define the new field by entering the field name, data type, optional description, and any property specificationsNew Perspectives on Microsoft Access 2010 15
  16. 16. Adding a Field Between XP Two Existing FieldsNew Perspectives on Microsoft Access 2010 16
  17. 17. Table Relationship XPNew Perspectives on Microsoft Access 2010 17
  18. 18. Importing Data from an Excel Worksheet XP • The import process allows you to copy the data from a source without having to open the source file • Click External Data on the Ribbon • Click the Excel button in the Import & Link group to start the wizardNew Perspectives on Microsoft Access 2010 18
  19. 19. Importing Data from an Excel Worksheet XPNew Perspectives on Microsoft Access 2010 19
  20. 20. Importing Data from an Excel Worksheet XPNew Perspectives on Microsoft Access 2010 20
  21. 21. Importing Data from an Excel Worksheet XPNew Perspectives on Microsoft Access 2010 21
  22. 22. Creating a Table by Importing an XP Existing Table Structure • Make sure the External Data tab is the active tab on the Ribbon • In the Import & Link group, click the Access button • Click the Browse button • Navigate to the file • Make sure the Import tables, queries, forms, reports, macros, and modules into the current database option button is selected, and then click the OK button • Click the Options buttonNew Perspectives on Microsoft Access 2010 22
  23. 23. Creating a Table by Importing an XP Existing Table StructureNew Perspectives on Microsoft Access 2010 23
  24. 24. Adding Fields to a Table Using the XP Data Type Gallery • The Data Type gallery, available in the Add & Delete group on the Fields tab, allows you to add a group of related fields to a table at the same time, rather than adding each field to the table individually • The group of fields you add is called a Quick Start selectionNew Perspectives on Microsoft Access 2010 24
  25. 25. Adding Fields to a Table Using the XP Data Type GalleryNew Perspectives on Microsoft Access 2010 25
  26. 26. Deleting a Field from a Table Structure XP • In Datasheet view, click the column heading for the field you want to delete • In the Add & Delete group on the Fields tab, click the Delete button or • In Design view, click the Field Name box for the field you want to delete • In the Tools group on the Design tab, click the Delete Rows buttonNew Perspectives on Microsoft Access 2010 26
  27. 27. Deleting a Field from a Table Structure XPNew Perspectives on Microsoft Access 2010 27
  28. 28. Adding Data to a Table by Importing XP a Text File • Click the External Data tab on the Ribbon • In the Import & Link group, click the Text File button • Click the Browse button • Navigate to the file • Click the Append a copy of the records to the table option button • Select the table • Click the OK buttonNew Perspectives on Microsoft Access 2010 28
  29. 29. Adding Data to a Table by Importing XP a Text FileNew Perspectives on Microsoft Access 2010 29
  30. 30. Defining Table Relationships XP • One of the most powerful features of a relational database management system is its ability to define relationships between tables • You use a common field to relate one table to anotherNew Perspectives on Microsoft Access 2010 30
  31. 31. Defining Table Relationships XPNew Perspectives on Microsoft Access 2010 31
  32. 32. Defining Table Relationships XP • A one-to-many relationship exists between two tables when one record in the first table matches zero, one, or many records in the second table, and when one record in the second table matches at most one record in the first table The Primary table is the “one” in a one-to- many relationship The Related table is the “many” tableNew Perspectives on Microsoft Access 2010 32
  33. 33. Defining Table Relationships XP • Referential integrity is a set of rules that Access enforces to maintain consistency between related tables when you update data in a database • The Relationships window illustrates the relationships among a database’s tables • Click the Database Tools tab on the Ribbon • In the Relationships group on the Database Tools tab, click the Relationships buttonNew Perspectives on Microsoft Access 2010 33
  34. 34. Defining Table Relationships XPNew Perspectives on Microsoft Access 2010 34
  35. 35. Defining Table Relationships XPNew Perspectives on Microsoft Access 2010 35
  36. 36. Defining Table Relationships XPNew Perspectives on Microsoft Access 2010 36

×