5.1. Designing Database Tables

First, there will be two tables added to your database: persons and phone_numbers. These are exactly the same tables as described in chapter 1.2. A database and a spreadsheet. A layout for Persons can be found in section Data integrity and validity in that chapter.

  1. Select Insert->Table from the Menubar. You can also use button Create object: table on the Project Navigator's toolbar (see section 4.6.1. Project Navigator pane).

  2. Table Designer's window will appear. Looking at the top of designer's window you will notice that Kexi proposed you a generic name like template for the new table. The table design is not saved yet so you will be able to assign more proper name later. Moreover, because of the same reason, the table name is not yet visible in the Project navigator.

5.1.1. Table Designer window

Table Designer window consists of following columns:

In Table designer window, every row corresponds to a single table field. You can recognize you are in design mode because the Switch to Design View mode button is toggled on within the main Kexi toolbar (see the figure below).

To start entering the Persons table design:

  1. In the first row click on the cell in Field name column and enter name field name.

    Entering names for table fields

    Notes about field names

  2. Use down arrow key to move to next row. In the Data Type column, Text type appeared automatically. This is what you actually expected since a person's name should be in fact of type text.

  3. In a similar way, enter the following fields into the table design:

  4. All above fields except house_number are of type text. Change house_number field's type to integer number. To do this, click on a cell in the Data Type column, house_number row and then click on drop down list's button (you can also press F4 or Alt+Down arrow keys). The list of data types will appear. Select Integer number type.

    Changing data type of a filed to integer number

    Since now, house_number field only acepts numbers.

  5. Persons table desgin is ready. Click Switch to Data View button on the toolbar to finish designing and switch to Data View for the table. This allows you entering data into the table.

  6. As the design is not yet saved in the database, "Save Object As" dialog window appears. You need to specify the name for the new table.

    Entering table name before saving its design

    Kexi offers a generic name like Table1. To change the name, enter Persons into the Caption field and press Enter key or click OK button. Caption field will be used to displaying the table to database end-users, e.g. as a form. Unlike the name, the caption can contain any characters including spaces a special characters.

    Note that filling Caption field automatically fills Name field. For your convenience the rule for using only latin letters, digits and the "_" character is kept. You can alter contents of the Name field if you want to.

    Example of automatically filled Name field

  7. You are asked about an agreement for automatic adding of primary key to the table. The idea of primary keys is described in chapter 6. Click Add primary key button to continue.

    A question about automatic adding a primary key

  8. Persons table has been created and opened in Data View. Its name appears in the Project Navigator pane.

    Persons table in the Project Navigator pane

  9. Create phone_numbers table, in a similar way as persons table.

  10. Create person field of type Integer number and phone of type Text. Do not use a number type here because phone number can have many different forms and prefixes.

  11. Click Switch to Data View button on the toolbar and enter Phones caption for the table. As for your previous table, allow Kexi to automatically create primary key.