Kexi/Handbook/Building Simple Databases/Designing Database Queries: Difference between revisions

From KDE Wiki Sandbox
(Marked this version for translation)
m (→‎Designing Database Queries: bold italic for variable data)
Line 19: Line 19:
<translate>
<translate>
<!--T:9-->
<!--T:9-->
# Add query relationship using mouse drag & drop technique: click the field id in the table persons table, drag it and drop into the person field of the '''''phone''''' table. This will join both fields by creating a new relationship. </translate>
# Add query relationship using mouse drag & drop technique: click the field '''''id''''' in the '''''persons''''' table, drag it and drop into the '''''person''''' field of the '''''phone''''' table. This will join both fields by creating a new relationship. </translate>
<!--FIXME Why have some field/table names in this sentence a replaceable markup, others not? Why have the same field/table names in this document different capitalisation? This happens at several other parts of this documentation as well-->
<!--FIXME Why have some field/table names in this sentence a replaceable markup, others not? Why have the same field/table names in this document different capitalisation? This happens at several other parts of this documentation as well-->
<translate>
<translate>
<!--T:12-->
<!--T:12-->
# Double-click the name field in the '''''Persons''''' table, to add the field as a query column. In a similar way, add '''''surname''''', '''''street''''', '''''house_number''''', '''''city''''' fields from the '''''Persons''''' table and phone from the '''''Phones''''' table. </translate>
# Double-click the '''''name''''' field in the '''''Persons''''' table, to add the field as a query column. In a similar way, add '''''surname''''', '''''street''''', '''''house_number''''', '''''city''''' fields from the '''''Persons''''' table and phone from the '''''Phones''''' table. </translate>
<translate>
<translate>
<!--T:10-->
<!--T:10-->

Revision as of 20:22, 12 April 2012

Other languages:

Designing Database Queries

A database's primary purpose is to store and help extract information you are looking for. Unlike databases written on a paper sheets, Kexi database allows you to specify more search criteria. Results are returned faster even for large data sets. All this is a power of databases, however to be able to perform effective queries in your database, you need to learn how to tell the database what you are looking for.

With database queries you can limit data coming from a table to a predefined set of rows and columns as well as dynamically join data coming from multiple tables.

To see how queries work in practice you will create a contacts query joining data from two tables: Persons and Phones (designed here and filled with data here).

  1. Create a new empty query by selecting Query from the toolbar. The design window will appear. The window is split into two areas: query relationships at the top and query columns below.
  2. Select the table Persons in the drop down list Table: located at the top of the window and click the Insert button. A graphical representation of the table will appear in the relations area. Do the same for the Phones table to insert it too.
  3. Add query relationship using mouse drag & drop technique: click the field id in the persons table, drag it and drop into the person field of the phone table. This will join both fields by creating a new relationship.
  4. Double-click the name field in the Persons table, to add the field as a query column. In a similar way, add surname, street, house_number, city fields from the Persons table and phone from the Phones table.
  5. Query design is now ready for testing. Click the Data button on the toolbar, to switch from design to viewing the data provided as query results.
  6. Save the query design for later use by clicking the Save button on the toolbar. Because the query design has not been saved yet, you will be asked to specify a name for it. Enter Contacts text in the caption field and click the OK button.