Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 3. Creating Data Tables (I)

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 21

Unit 3.

Creating data tables (I)


Here we will see how to create a data table in order to be able to introduce data into the database in the following units, and later work with this data using the advantages provided to us by Access2003.

Creating a data table.


To create a data table we need to position ourselves in the database window with the Tables object selected, if we click on the New button it opens a window with the various available ways of creating a new table: Datasheet view consists of directly introducing the data into the table, and according to the value introduced into the column determines the type of data that the column has. Design view is the method we will detail in this unit. Table wizard guides us step by step in the creation of the table using a predetermined sample table. Import table consists of creating a new table from an existing one in another database. Link table consists of creating a reference to another table stored in a different database. Next we will explain the way to create a table in design view. This method consists in defining the structure of the table i.e define the different columns that it will contain as well as other considerations such as codes, validation rules etc... Another way to arrive at the design view is from the Database window with the Tables object selected then double clicking on the option Create table in Design view.

The Table design window will appear:

In the title bar we have the name of the table (as we have still not assigned a name to the table, Access has assigned a default name Table1. Next we have a grid where we define the columns (fields) that compose the table using a line for each column, so in the first row of the grid we will define the first column of the table, in the second row of the grid we will define the second column of the table and so on and so on. At the bottom left we have two tabs (General and Lookup) to define the properties of the field i.e additional characteristics of the column we are defining. And on the right we have a box with text to help us with what we need to accomplish. To continue, go to the next page. Unit 3. Creating data tables (II) We will fill in the grid defining each of the columns that compose the table:

We can define a field using the field builder which allows us to define fields from those in sample tables and are activated clicking on the button on the toolbar. For more information on the Field builder clic here .

Or we can define our own fields as explained next. In the first row write the name of the first field, and by pressing the ENTER key we move to Data Type column, which by defect will be Text. Should we choose to change the type of data, click on the arrow of the drop down list and select another type. For more information on different data types clic here If you require more information on the Lookup Wizard... clic here .

When we choose a type for the data, at the bottom of the window, the Field properties section is activated so as to be able to indicate more characteristics for the field, we will look at these characteristics in detail in the next unit. Press ENTER next to go to the third column of the grid. It is not necessary to use this column as it only serves to write comments; usually a description of the field for the person who will be introducing data so as to know what to write, this comment will appear on the status bar on the data page. Repeat the process until all the fields (columns) in the table have been defined. The primary key Before saving the table we need to assign a primary key. The primary key provides a unique value for each row in the table and serves to identify the records in such a way that with this key we can be sure of not mistaking the record being identified. In a table we can not define more than

one primary key, but we can have a multiple-field primary key (one primary key defined on several fields. To assign a primary key to a field follow these instructions: Click on the name of the field that will be the primary key. Click on the Primary key button on the toolbar.

On the left of the field name will appear a key indicating to us that this field is the primary key of the table. If we want to define a multiple-field primary key (based on various fields), hold down the Ctrl key and click on all those fields, then click on the button.

Important: Remember that a field or group of fields forming the primary key of a table cannot contain null values and neither have two rows in the table with the same value in the primary key fields. When we try to insert a new row with values that infringe on these two rules the system will not allow us to create the row and will return an error. Saving a table. To save a table we need to: Go to the File menu and select Save. Or click on the Save button on the toolbar.

As our table does still not have a name, the following dialogue box will appear: Write the name of the table. Click on the OK button.

Note: If we have not assigned a primary key before saving the table, a dialogue box will appear advising us of this, and asking whether we would like Access to create one like this:

If we decide Yes, it will create a Autonumber field and will define it as the primary key. If we decide No, the table is saved without a primary key, a primary key is convenient but not obligatory. Closing a table. To close a table, follow these steps: Go to the File menu and select the Close option. Or, clic in the Close button in the Database window.

To practise what you have learnt, you can perform the Step by step Exercise Tables Creation.

Data Types
When creating a table, one will need to specify what kinds of data are to be stored in this field. The different kinds of Access2003 data are: Text: allows for the storage of any kind of data, characters, digits and special characters. It has a defect length of 50 characters with a maximum length of 255. It is normally used to store data such as names, addresses, or any number not used in calculations, like telephone numbers or zip codes. Memo: is used for texts of more than 255 characters such as comments or explanations. It has a maximum length of 65.536 characters. Access recommends that to store formatted text or large documents, rather to create an OLE Object field than a Memo field. In Access2003 it is possible to arrange or group in a Memo field, but Access only uses the first 255 characters when it arranges or groups in a Memo field. Number: for numerical data used in mathematical calculations. Within the number type we are able to specify the size property of the field. The types Byte, Integer and Long Integer allow the storage of numbers without decimals;

the types Single, Double and Decimal allow decimals; the type Replication ID is used for autonumerical codes in replication databases. Date/Time: for the introduction of date and time from the year 100 to 9999. Currency: For monetary values and numerical data used in mathematical calculations in which the data involved contains between one and four decimals. The accuracy is up to 15 digits to the left of the decimal separator and up to 4 digits to the right of the same. Access recommends the use of Currency type to avoid the rounding off of numbers in calculus. A Currency field has an accuracy of up to 15 digits to the left of the decimal separator and 4 digits to the right. A Currency field occupies 8 bytes of space on disc. Autonumber: a unique sequential number (increasing one by one), or an aleatory number that Access assigns every time it adds a new record to a table. Autonumber fields can not be updated. Yes/No: Yes and No values, and fields that contain one of two values (Yes/No, True/False or Acivated/Disactivated). OLE Object: an object such as a Microsoft Excel spreadsheet, a Microsoft Word document, graphics, images, sounds, or other binaries. Hyperlink: text or a combination of text and numbers stored as text and used as a hyperlink address. A Hiperlink is a text or grafic that you click to go to a file, a location in a file, a web page on the Internet, or a web page on an intranet. Another possibility exists which is the Lookup wizard... which creates a field that allows you to choose a value from a list. Access can fill the list with values from a table or with values you type. The Lookup Wizard (I) The lookup wizard On some occasions, the value introduced in a column can not be of just any kind, but needs to be extracted from a list of valid values for this particular field. For example, the field Sex with the values M or F, a State field with values (FL, TX, NY, etc...). This list of values can be fixed values that we type or it can be a list of values extracted from an existing table in our database (for example from a table that contains all states). In Access we can define this list of valid values easily and quickly using the Lookup wizard. To start the wizard you will need to position yourself in the design window of the table over the type of data field that will contain the data extracted from the list and select Lookup wizard...

Next will appear the first screen of the wizard where we are asked whether we want to obtain the values of a specific table or query, or if we would like to write the values.

Search column based on a list of values.

If we select the second option (I will type in the values that I want) a second screen appears where we need to indicate the values filling the column.

Once we have introduced all of the values press the Next> button to continue to the next screen where we can type a name for the column.

All we need to do now is click on the Finish button.

The Lookup tab - List of values. With the wizard we have defined the field with a search list based on a list of values, we see this reflected in the fileds properties in Lookup tab in the following way.

The properties that appear will show us the folowing: Display control: A Combo box, indicate we can type a value or we can click on the box to display the list and choose one of values. Row source type: In our case its a list of values that we had introduced. Row sourse: in this property we have the different values of the list separated by semicolons. Bound Column: determines which column Access will get from the value to store in the field. Column Heads: Determines whether a first line with column headers will appear in the drop down list. If this property contains the Yes value, it will take the first line of values as the column headings. Columns Widths: etermines the width of every column on the list. If there are various columns widths will be separated by semicolons. List Rows: determines how many rows are displayed when the list drops down. List Width: indicates the total width of the list. Limit to list: if this property contains No, we can introduce a value that is not in the list, whilst if we indicate Yes, the value needs to be one of those on the list. If the user tries to enter a value not contained in the list, Access will return an error message and will not allow this value to be saved.

Step y step exercise. Creating a Table. Objective. Practising the procedures to create and open a data table with Access2003. 1 If Access is not open, open it to be able to carry out the exercise. 2 Open the Classes.mdb database which is found in the My documents folder. We are going to create two tables in the database. One table will be for the students and the other for the courses. We will start by creating the Students table. 3 Double click on Create table in design view in the database window with Tables object selected. Or, click on the New button in the database window, select Design View, and click on the OK button.

4 In the first row write the name of the first field, Student Code. 5 Press the ENTER key to go to the second column of the field. 6 By default, once situated in the second column the Data Type is Text, click on the arrow on the right and select Autonumber. 7 Press the ENTER key to go to the third column, but we will not use it. For the moment we will not change the properties of this field. 8 Press the ENTER key to go to the next field. 9 Write Student name as the Field Name of the second field. Leave Text as Data Type and position yourself in the third column. 10 In the Description column in the grid write: Type the student name. Press ENTER to go to the next column. 11 Write Student surname. 12 Press ARROW BELOW on the keyboard to go to the next row. 13 Now create the following fields: Address, City which will all be of the Text type and Postcode as numeric. 14 Next create a Date of birth field with Date/Time data type. Now we are going to make Student code the Primary key so as not to have two students with the same code.

15 Click on Student code. 16 Click on the Primary key button on the taskbar.

To the left of the field name a key will appear, indicating that this field is the primary key of the table. Now we can save the table. 17 Drop down the File menu. 18 Select the Save option. 19 When asked for the name of the table, write Students. 20 Click on the OK button. Now we will close the table. 21 Drop down the File menu. 22 Select the Close option. Now we will create the second table: 23 Click on the New 24 Select Design View. 25 Click on the OK button. 26 In the first row write the name of the first field, Course code. 27 Press the ENTER key to go to the second column of the field. 28 Choose as Number as Data Type. 29 Press the ENTER key to go to the third column of the field. 30 Press the ENTER key to go to the next field. 31 Type Course name as the name in the second field of the table. 32 As we do not wish to change any of the other characteristics of the field, press the ARROW BELOW to go to the next field. button in the Database window.

33 Type Hours , and select data type Number. (you can drop down the list or type the first letter (N)) 34 Create the following fields: Start date and Finish date - data type: Date/Time. Now we will define Course code as the Primary key. 35 Click on Course code. 36 Click on the Primary key button on the taskbar.

On the left of the field name a key will appear, indicating that this field is the primary key of the table. Now we can save the table. 37 Click on the Save button on the toolbar.

38 Type Courses as the name of the table. 39 Click on the OK button. 40 Click on the Close 41 Click on the Close button in the Design window of the table. button in the Database window to close to database.

Unit 4. Modifying data tables (I)


Here we will see the record editing techniques used to modify a table definition as well as the data introduced into it.

Modifying the design of a table.


If we wishmake an alteration in the definition of an existing table (e.g to add, extend or delete an existing column etc...) we need to make a modification in its design. Open the database where the table we want to modify is found if you are not already there. Select the table that you want to modify by clicking on it so that its name stands out. Click on the Design button in the database window.

The Table Design window studied in the previous unit will appear.

To modify a field design, position the cursor over the field to modify, and perform the necessary substitutions. To add a new field, go to the end of the table and type in the new field definition. or, situate yourself in an already existing field and click on the button in the Table Design bar, in this last case the new field will be inserted before the one in which we are positioned. To delete a field, position yourself in the field and click on the or, select the whole row corresponding the field by clicking on its extreme left, and when it stands out press the Del key. The field, as well as the data stored in it will be erased from the table. button in the Table Design bar.

And lastly, save the table. To practice these operations you can perform the Step by step Exercise Modifying the table design.

Step by step exercise. Modifying a data table. Objective. Practise the procedures for modifying the design of a table with Access2003. 1 If Access is not open, open it to be able to carry out the exercise. 2 Open the Classes.mdb database, found in My Documents in the hard drive. We are going to modify the structure of the Students table:

Field Student Surname

Properties Introduce the commentary Type the Student surname This field does not exist, add it and it will allow us in unit 6 to make the relationship between the tables Students and Courses. Data Type:Number This field does not exit, add it and we will use it to practise creating and erasing fields. Data Type: Text

3 Select the Students table by clicking on it. 4 Click on the Design button in the Database window.

5 Click on the Description column of the Student Surname field. 6 Write the text Type the Student surname. Now we are going to add the Course field: 1 Click on the Description column of the first empty row (below Date of Birth). 2 Type Course. 3 Press ENTER key. 4 Drop down the data types list and select Number. 3 Press ENTER key. Now we will add the Auxiliary field. 1 In the next row of the grid type Auxiliary in the first column. As the field is Text we have finished with its creation. Now we will erase the Auxiliary field. 1 Click on the row corresponding the field Auxiliary so as to position the cursor in this field.

2 Click on the

button on the toolbar.

The field will dissapear. As we have now finished with the design of the table we will now save it. 3 Click on the Save button on the toolbar and close the window.

Introducing and modifying data in a table.


To introduce data into a table we can choose: - In Database window, select the table to fill in by clicking on its name and click on the table. - In Database window, double click on its name. - If you are in Table design window, click on the Datasheet In all three cases the Datasheet window will appear: button in the Table design bar. button to open the

Each rows allow us to introduce a record. Write the value of the first field of the record. Press ENTER to go to the next field in the record. Once we have finished introducing all data in fields in the first record, we press ENTER key to introduce the data in the second record. The moment we change to a different record, the record that we were in will be stored, and it is therefore not necessary to save the records again. Click on the Close button in the Datasheet window to conclude this table.

If we want to delete an entire record:

Select the record to eliminate by clicking on the box on its extreme left (named record selector). The record will remain selected. Press the DEL key on the keyboard or on the button on the Datasheet bar.

Is we need to modify an inserted value all we need to do is situate ourselves over the value and re-tyte it. If we need to alter something in the tables' structure, we will need to go to Design view by clicking on the button on the Datasheet bar. To practice these operations you can perform the Step by step Exercise Introduce data. Step by step exercise. Introduce data into a table. Objective.

Practise the procedures for introducing and modifying data in a table with Access2003.
1 If Access is not open, open it to be able to carry out the exercise. 2 Open the Classes.mdb database, found in My Documents in the hard drive. 3 Select the Students table by clicking on it. 4 Click on the Open button in the Database window.

Observe how in the first field we put (Autonumber) as the type of data assigned to the Students Code. We do not need to w fills in automatically. 5 Press ENTER to go to the next field. 6 Write the name John as Student Name. Observe how in the Student code field now has a value of 1. 7 Press ENTER to go to the next field and write Smith as surname. 8 Press ENTER to go to the next field and write 34 Green as address. 9 Press ENTER to go to the next field and write Los Angeles. 10 Press ENTER to go to the next field and write 46002 as Postal code.

11 Press ENTER to go to the next field and write 02/15/73 as Date of Birth. 12 Press ENTER to go to the next record. 13 Add the records that appear in the next table. Note: the field Course will be left empty for the moment as we have not yet created the courses.

Now we are going to correct the name of student 4, we type Ane instead of Anne by mistake. 14 Click on the word Ane between n and e letters and type an 'n'. 15 Close the table by clicking on the Close 16 Close the database by clicking on the Close button on the Datasheet window. button on the Database window.

Moving within a table.


To move around the various records contained in a table we can use the Navigation buttons:

The bar indicates to us which record we are in and the total number of records in the table. The current record is indicated in the white box. In the final number where we see of 3, the total number of records is indicated to us. By clicking on the different buttons we can perform the operations explained next: to go to the first record in the table.

to go to the previous record in the table. to go to the next record in the table. to go to the last record in the table. To create a new record that is automatically situated at the end of the table. We can also go directly to a determined record in the following way: Double clic in the white box where the current record number is situated. Write the number of the record we want to go to. Press ENTER. We can also move around the different fields and records by pressing the ARROW UP, ARROW LEFT, ARROW DOWN, and ARROW RIGHT keys on the keyboard. To practice the operations studied you can perform the Step by step exercise Moving within a table. Step by step exercise. Moving within a table. Objective. Practise the procedures for moving all through the records in a table with Access2003. 1 If Access is not open, open it to be able to carry out the exercise. 2 Open the Classes.mdb database, found in My documents in the hard drive. 3 Open the Students table in Datasheet View by double clicking on it. Observe how the active record is the first one. 4 Click on the button on the bar below to go to the next record.

Observe how in the white box on this same bar it is indicated which record we are in (now, the second one). 5 Click on the 6 Click on the 7 Click on the button to go to the last record. button on the bottom bar to go to the previous record. button to go to the first record.

8 Click on the

button to create a new record.

Observe how the cursor is now situated in the last row of the table. 9 Insert the following records.

Students Code 9 10

Student Name Student Surname Louise Tom Menor Smith

Address 27 Valley rd. 34 Major rd

City Los Angeles Los Angeles

Postal Code 46002 46005

Date of Birth 04/25/65 10/30/62

Now we will go to record 4. 10 Double click on the number of the current record on the bottom bar. 11 Type 4 and press ENTER key. Observe how the cursor is now situated in the fourth record. 12 Close the table by clicking on the Close 13 Close the database by clicking on the Close button in The Datasheet window. button in the Database window.

Unit 4. Modifying data tables (II)


Find and replace data.
We will often need to search for a record when knowing the value of some of its fields. In order to perform this operation we have at our disposal the Access2003 Find tool. In order to use this tool we need to visualize the data in Datasheet view, next position the cursor in the column that we want to search in, and finally drop down the Edit menu and select the Find... option, or click on the button on the toolbar. The Find and replace dialogue box will appear next:

In the Find What: box, we write the value to find. In the Look in: box we indicate the field where the value being searched for can be found. By defect it will take the field in which we have the cursor at that moment, and if we want it to look in any other field we can select the name of the table from the list. In the Match: box, we select one of these three options:

Whole field so that the value being looked for coincides exactly with the value introduced in the field. Any part of the field so that the value being looked for is found in the field but does not need to coincide exactly. Start of field so that the value being looked for is the initial part of the field. After this we can indicate in Search: All so that it will look in all the records of the table. Up so that it will look in all the records from the first until the one we are currently situated in. Down to look from the record we are currently in until the last. If we activate the Match Case box then Access will differentiate between upper or lowercase at the time of the search (if we are searching for Mary we will not find mary). We can click on the Find next button to start the search, and it will position us in the first record that match the search requirements. If we wish to continue the search we can click on the Find next button succesively until we

find the record that we are searching for. Close the dialogue box after this. If we want to substitute a value with another we can use the Replace option. To make use of this tool we must be in Datasheet view, then position the cursor in the field we wish to replace, and finally drop-down the Edit menu and select the Find... option, or click on the button on the toolbar, and click on Replace tab.

The Replace tab has the same search options than the Find tab we have seen before, and these ones: In the Replace with: box also we type the substitution value. With the Replace button, the value that we are currently positioned in will be replace. With the Replace All button all the values found will be replace. We need to be very careful with this option so that we do not get undesired results, especially if we do not use the Whole field option. To practice these operations you can perform the Step by step Exercise Searching for data in a table.

You might also like