Define Keys

Define a primary key

Every table in OOBase needs to have a primary key defined. The is a field (or fields) that uniquely identify a record. In other words no two records can contain the same number in the primary key field. In the Customers table we have a field called CustomerID which should be set to the primary key in this case. This means that each customer will have it's own unique identifying number. If you use a field such as the Name as a primary key it will probably not work as you may find companies with the same name. Sometimes you can use an existing field such as ID number as a primary key field. If you do not have a field that is suitable to use as the primary key then you will need to create one such as CustomerID to act as the primary key.

To set a field as a primary key, click on the grey button next to the field name in and right click to activate the pop up menu. Click on Primary Key. You will see a small yellow key appearing next to the field name.

Index a field with, without duplicates allowed

An index improves performance by providing an alternate path to access data and speeds up searches, sorting, queries etc.

To create an index click on Tables and open in Edit mode. Click on Tools > Index Design or click on the icon on the toolbar. Figure 14 shows an example of the first Index Design screen.

Figure 2.6. Creating a new index

Creating a new index

Click on the first icon to create a New Index. A new index is created on the left hand side called Index1 which you can rename. In the example in Figure 15 the index has been renamed to Surname. On the right hand side you will need to select the field you want to create the index on, in this case it is the surname field and the sort order is Ascending.

Figure 2.7. Renaming the index

Renaming the index

Notice that there is an option to make this a unique index. In other words if you do not want duplicate entries here you would click on Unique. This would not work here as there are going to be instances where many people have the same surname. However, if you were creating the index on a field like an account number you would then choose not to allow duplicates by activating the Unique option.

Remember to save the index by clicking on the save button. If you have not saved and you click on the close button you will get the following prompt “Do you want to save the changes made to the current index? At this point you could save.