You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
koffice/kexi/doc/handbook/html.tmp/05_01_00_table_designing.html

110 lines
6.9 KiB

<H2>5.1. Designing Database Tables</H2>
<p>
First, there will be two tables added to your database: <em>persons</em> and <em>phone_numbers</em>. These are exactly the same tables as described in chapter <a href="01_02_00_db_spreadsheet.html">1.2. A database and a spreadsheet</a>. A layout for <em>Persons</em> can be found in section <a href="01_02_00_db_spreadsheet.html#data_integrity">Data integrity and validity</a> in that chapter.
</p>
<p>
<ol>
<li><p>
Select <em>Insert-&gt;Table</em> from the Menubar. You can also use button
<img src="icons/table_newobj.png" class="icon"> <em>Create object: table</em> on the Project Navigator's toolbar (see section <a href="04_06_01_project_navigator.html">4.6.1. Project Navigator pane</a>).
</p></li>
<li><p>
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 <em>template</em> 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 <a href="04_06_01_project_navigator.html">Project navigator</a>.
</p></li>
</ol>
<a name="design_window"></a>
<H3>5.1.1. Table Designer window</H3>
<p>
Table Designer window consists of following columns:
<ul>
<li><b>PK</b> - Primary key. It will be discussed this topic in <a href="06_00_00_idx_building_advanced_database.html">chapter 6</a>.</li>
<li><b>Filed Name</b> - field name (in other words: column name) which will be visible during data entering.</li>
<li><b>Data Type</b> - 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 integer number data type is set for a field, database user will not able to enter a letter characters into this field.
<!-- More information about data types is available in section <a href="??_??_??_datatypes.html">???. Data types</a>. -->
</li>
<li><b>Comments</b> - you can enter here any informations useful for understanding what the given field is provided for. This additional text will be saved within the table design and only visible when it is designed.</li>
</ul>
</p>
<p>
In <em>Table designer</em> window, every row corresponds to a single table field. You can recognize you are in <em>design mode</em> because the <nobr><img src="icons/state_edit.png" class="icon"> <em>Switch to Design View mode</em></nobr> button is toggled on within the main Kexi toolbar (see the figure below).
</p>
<p>
To start entering the <em>Persons</em> table design:
<ol>
<li>
<p>In the first row click on the cell in <em>Field name</em> column and enter <kbd>name</kbd> field name.
<br><img src="img/05_01_00_defining_columns.png">
<br>Entering names for table fields<br><br>
</p>
<a name="note_field_names"></a>
<H4>Notes about field names</H4>
<p>
<ul>
<li>You must not left name for any of your fields empty.</li>
<li>Field names could not contain natonal character (like <20>, <20>, <20>), special characters or space characters. The names must only contain roman letters, numbers and underscore sign &quot;_&quot;. Use the latter instead of spaces or dashes.</li>
<li>Field names must be started with a roman letter or underscore sign &quot;_&quot;, never with a number.</li>
<li>It does not matter whether you are using small or capital letters. For Kexi databases, &quot;Persons&quot; is the same ad &quot;persons&quot; name.</li>
</ul>
</p>
</li>
<li><p>
Use down arrow key to move to next row. In the <em>Data Type</em> column, <em>Text</em> type appeared automatically. This is what you actually expected since a person's name should be in fact of type text.
</p></li>
<li><p>
In a similar way, enter the following fields into the table design:
<ul>
<li><kbd>surname</kbd></li>
<li><kbd>street</kbd></li>
<li><kbd>house_number</kbd></li>
<li><kbd>city</kbd></li>
</ul>
</p></li>
<li><p>
All above fields except <kbd>house_number</kbd> are of type text. Change <kbd>house_number</kbd> field's type to <em>integer number</em>. To do this, click on a cell in the <em>Data Type</em> column, <kbd>house_number</kbd> row and then click on drop down list's button <img src="icons/dropdown_button.png" class="icon"> (you can also press F4 or Alt+Down arrow keys). The list of data types will appear. Select <em>Integer number</em> type.
<br><img src="img/05_01_01_changing_datatype.png">
<br>Changing data type of a filed to integer number<br><br>
Since now, <kbd>house_number</kbd> field only acepts numbers.
</p></li>
<!-- TODO setting additional properties: e.g. caption -->
<li><p>
<em>Persons</em> table desgin is ready. Click <nobr><img src="icons/state_data.png" class="icon"> <em>Switch to Data View</em></nobr> button on the toolbar to finish designing and switch to Data View for the table. This allows you entering data into the table.
</p></li>
<li><p>
As the design is not yet saved in the database, &quot;Save Object As&quot; dialog window appears. You need to specify the name for the new table.
<br><img src="img/05_01_01_entering_table_name.png">
<br>Entering table name before saving its design<br><br>
Kexi offers a generic name like <em>Table1</em>. To change the name, enter <kbd>Persons</kbd> into the <em>Caption</em> field and press <kbd>Enter</kbd> key or click <em>OK</em> button. <em>Caption</em> 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.
<br/>
<br/>
Note that filling <em>Caption</em> field automatically fills <em>Name</em> field. For your convenience the rule for using only latin letters, digits and the &quot;_&quot; character is kept. You can alter contents of the <em>Name</em> field if you want to.
<br><img src="img/05_01_01_automatic_names.png">
<br>Example of automatically filled Name field<br><br>
</p></li>
<li><p>
You are asked about an agreement for automatic adding of primary key to the table. The idea of primary keys is described in <a href=""><!-- TODO chapter # -->chapter 6</a>. Click <em>Add primary key</em> button to continue.
<br><img src="img/05_01_01_pkey_recommended.png">
<br>A question about automatic adding a primary key<br><br>
</p></li>
<li><p>
<em>Persons</em> table has been created and opened in Data View. Its name appears in the Project Navigator pane.
<br><img src="img/05_01_01_table_created.png">
<br><em>Persons</em> table in the Project Navigator pane<br><br>
</p></li>
<li><p>
Create <em>phone_numbers</em> table, in a similar way as <em>persons</em> table.
</p></li>
<li><p>
Create <kbd>person</kbd> field of type <em>Integer number</em> and <kbd>phone</kbd> of type <em>Text</em>. Do not use a number type here because phone number can have many different forms and prefixes.
</p></li>
<li><p>
Click <nobr><img src="icons/state_data.png" class="icon"> <em>Switch to Data View</em></nobr> button on the toolbar and enter <em>Phones</em> caption for the table. As for your previous table, allow Kexi to automatically create primary key.
</p></li>
</ol>