# Construir bases de datos sencillas

## Introducción

To learn the basics of &kexi;, you could build a simple database utilizing most elementary &kexi;'s features. To make things simpler, advanced database design topics will not be covered here.

Comience creando una Agenda telefónica nueva.

En un proyecto nuevo de base de datos vacía, realice los siguientes pasos:

1. Diseñar tablas de bases de datos. Puede leer .

2. Introducir datos en tablas. Puede leer .

3. Diseño de consultas de base de datos. Puede leer la sección (PENDIENTE)

4. Diseño de formularios. Puede leer la sección (PENDIENTE)

5. Utilizar formularios para introducir datos. Puede leer .

## Diseñar tablas de base de datos

Primero se añaden dos tablas a su base de datos: personas and nums_tlf. Son exactamente las mismas tablas que se describen en el capítulo Bases de datos y hoja de cálculo. Se puede encontrar un diseño para Personas en la sección Integridad y validación de datos de este capítulo.

1. Seleccione Insertar Tabla en la barra de menú. También puede usar el botón Crear objeto: tabla sobre la barra de herramientas del Navegador de proyectos.

2. The 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.

### La ventana Diseñador de tablas

#### La ventana Diseñador de tablas consta de las siguientes columnas:

- PK - Primary Key.

- Field Caption - caption of the field which will be displayed during data entering.

- Data Type - a combo box containing a list of data types, allowing to set a main rule for entered data for a given field. For example, when an integer number data type is set for a field, a database user will not able to enter letter characters into this field.

- Comments - you can enter here any information useful for understanding what the given field is provided for. This additional text will be saved within the table design and only visible in design mode.

In the 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.

#### Diseñar la tabla Personas

1. In the first row click on the cell in the Field Caption column and enter Name as field caption.

   #### Notes about field names and captions

   - Every table field must have a name and a capation, these cannot be empty.

   - Field name is a word used by the database, usually not visible for users of the database application. The name may not contain special (national) characters (like ±, ¶, Ü) or space characters. The name must only contain roman letters, numbers and underscore sign "_". Use the latter instead of spaces or dashes.

   - Los nombres de los campos deben comenzar con una letra o con un carácter de subrayado "_", nunca con un número.

   - No importa si usa mayúsculas o minúsculas. Para &kexi;, el nombre de las bases de datos "Personas" es igual que el de "personas".

   - Field caption, on the other hand, allows you to enter any letters and special characters. It will be displayed for users of the database application.

2. #### De igual modo, debe introducir los campos siguientes en el diseño de la tabla:

   - apellido

   - calle

   - num_casa

   - ciudad

3. All the 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. The list of data types will appear. Select the Integer number type.

   A partir de ahora, el campo num_casa sólo acepta números.

4. Persons table design 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.

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

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

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

6. You are asked about an agreement for automatic adding of primary key to the table. Click Add primary key button to continue.

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

8. Create the phone_numbers table, in a similar way as persons table.

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

10. 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 a primary key.

&enteringdataintotables; &querydesigning; &designingforms; &enteringdatausingforms;