Database Applications
Database Applications
Database Applications
6.1 Introduction ............................................................................................................................................ 2 6.1.1. Definitions ...................................................................................................................................... 2 6.2. Microsoft Access .................................................................................................................................... 3 6.3. Tables ..................................................................................................................................................... 4 6.3.1. Creating Tables................................................................................................................................ 4 6.3.1.1. Creating Tables in Design View ................................................................................................ 4 6.3.1.2. Creating a Table by Entering Data ........................................................................................... 5 6.3.2. Modifying the Table Structure ........................................................................................................ 6 6.3.3. Entering and Modifying Data .......................................................................................................... 6 6.3.4. Sorting the Data .............................................................................................................................. 6 6.4. Relationships .......................................................................................................................................... 7
Database Applications
Database Applications
6.1 Introduction
A simple definition of a database is a structured collection of related data about one or more subjects. Databases generally come in one of two styles: flat file and relational. Flat File Databases are basically used for simple lists and may have duplication of data much like a simple record card system. Relational databases are those where the data is held in a number of cross-referenced files in order to reduce duplication. They make it easier to find, analyze, maintain and protect data because it is all held in one place. Nowadays, relational databases are used widely to store data. Therefore, we will discuss only relational databases from now on.
6.1.1. Definitions
A collection of data relevant to a given subject is held in a Table. A Record is information that is related to a single item. A Field is an individual data item held for each record. Fields can be further defined in terms of size, type of information, possible values etc.
Field (Column)
Table
Employee No
Record (Row)
Date Appointed 10th June 2004 12th May 2003 2nd January 2005
Each table should be allocated a primary key. A Primary Key is a field or combination of fields which uniquely identifies the record in a table. The primary key field must always contain a value (i.e it cannot be NULL). Foreign keys should be maintained to establish relationships among different tables. A Foreign Key is a field in one table which is equal to the primary key column in another table. There should be relationships among tables in the database. The three types of relationships are: oneto-many; one-to-one; and many-to-many. Microsoft Access uses the following notations: A line indicates a relationship between two tables. A figure 1 at the end of a line indicates the one side of a relationship. The infinity symbol at the end of a line indicates the many side of a relationship.
Database Applications
Microsoft Access consists of many types of objects such as tables, queries, forms, reports etc. It is possible to move between the different objects by clicking on the relevant drop down menu called All Access Objects in the left-hand side of the window. Then, the selected objects will be shown below the menu.
Database Applications
6.3. Tables
6.3.1. Creating Tables
Microsoft Access provides various methods of creating tables. In this unit, we will look at the basics of creating tables in Access. More advanced details will be considered in the Database Development unit in the Advanced course. 6.3.1.1. Creating Tables in Design View Select, create => Table Design The following screen will appear.
Type the field names of each field one below the other in the Field Name column. For each field, select the data type from the drop down that appears in the Data Type column. The field types used commonly are text, number, date/time and currency. The auto number field type automatically enters a number beginning with 1 and saving consecutive values for each record. A description can also be entered against each field. Once all field details are entered, save the table. A popup window will prompt for the name of the table. If no primary key is defined, a dialog box will appear asking whether to create a primary key. If Yes is selected, an additional column will be added to the table and this column will be taken as the primary key.
Database Applications
It is possible to specify the primary key before saving the table. Click on the relevant field and click the Primary Key button in the ribbon.
Close the table window. The newly created table will appear as an item in the left-hand pane of the database window when the Tables dropdown is selected.
6.3.1.2. Creating a Table by Entering Data Select create => Table The following screen will appear.
Directly enter the data into the different fields in the table. Right click on each column and select Rename Field. Enter the column name. Once all data is entered, save the table. A popup window will prompt for the name of the table. If no primary key is defined, a dialog box will appear asking whether to create a primary key. If Yes is selected, an additional column will be added to the table and this column will be taken as the primary key. Close the table window. The newly created table will appear as an item in the left-hand pane of the database window when the Tables dropdown is selected.
Database Applications
Database Applications
6.4. Relationships
Relationships can be created between tables (and queries). When a relationship is created, one table acts as the master table and the other table acts as the child table. The primary key field in the master table should exist as a non-primary key field in the child table. The data type and size of the corresponding fields in the two tables must match exactly. Create the tables among which the relationship exists. Define the primary key of each table. Set the field type and size of the matching column in the child table to the same field type and size as the primary key in the master table. Select Database Tools => Relationships icon in the ribbon. A dialog box will appear. The Tables tab page of this dialog box will contain a list of tables that are defined in the database. Select each table that needs to be related and click Add. Use this method to add both the master and child tables to the relationship window. The relationships window will be displayed.
Database Applications