Creating a Table


Once you've set up your database file, you're ready to add tables to it. We'll create one table to store data about CDs.

  1. Click Tables on the left under the Objects heading.

  2. Expand the entry on the right of the window that shows the database filename you entered previously, and then double-click Create New Table.

  3. You're asked to give a name to the table. Once again, keep the name short but descriptive, and avoid using spaces.

After this, you'll be shown something that looks very similar to the Design View option within Microsoft Access. You can create data fields (known within Rekall as columns), set what type of data they contain, and enter a description for future reference.

Creating the Primary Key

The first field to create is the primary key. All tables need one of these because they uniquely identify each row of data. Doing so in Rekall is very simple. Just enter PrimaryKey into the first name box, select Primary Key from the Type drop-down list, and (if you wish) enter a comment in the Description box to remind yourself what the field does. Figure 27-3 shows the primary key entered in the table.

image from book
Figure 27-3. The first step in making a table to hold your data is to create a primary key.

Note 

The primary key automatically updates itself when new data is entered, so there's no need to set the field to do this, as with some versions of Microsoft Access.

Adding Columns

After setting up a primary key, you must enter columns for the data you want to enter. In our example of a CD database, we'll add columns to contain the artist information, the title of the CD, the year of release, notes, and an indication of whether the CD is scratched. You can add as many columns as you wish.

Along with the column name, you must specify its data type. For example, a Rekall table column might consist of nothing but whole numbers, so it would be a Number type. A column that holds text would be a Char type. Table 27-1 shows the various Rekall data types.

Table 27-1. Data Types Within a Rekall Table

Data Type

Description

Primary Key

A column that holds the number that identifies a particular row of data as being unique. Practically all databases must have a Primary Key column.

Foreign Key

Used in place of a primary key in some circumstances, particularly when interfacing with certain types of database servers. When creating simple data- bases with Rekall, this is not a data type you should use or worry about.

Bool

Stands for Boolean; used to define columns that hold one of two values: true or false. This data type is useful for creating check boxes in database forms.

Number

For whole numbers, without any decimal places. Numbers can range from minus two billion to plus two billion.

Float

For numbers that have (or might have) decimal places, such as 3.1415926.

Date

For columns that hold a date of some kind, whether that's a simple day and month or a day, month, and year (you will be able to choose the formatting of dates and times later). For what it's worth, years can go back to 1752 and up to 8000 AD.

Char

Short for characters; used to hold practically any amount of text, both letters and numbers.

Binary

Used to define a column that can contain files, such as images or multimedia files.

Why do you need to specify data types? Because it helps when the data is manipulated later on. For example, knowing that a field contains dates means that various tools can be created and used to manipulate the date information. In a similar fashion, if a data column can contain only numbers, then these numbers can be added, multiplied, and so on, without the worry of rogue letter characters jamming the formulas.

The principal data type we'll be using in the creation of our CD database is the Char type. This is designed to hold alphanumeric characters, and so is perfect for entering details about CDs such as titles and artist information.

So let's get started creating data columns.

  1. Enter Artist in the second Name box. Then select Char from the Type drop-down list. If you wish, enter some details in the Description box (although you can leave the Description box blank).

  2. Add a data column for the CD title named Title with a Char data type. You can move from text box to text box by pressing the Tab key.

  3. Add a data column for the CD year named ReleaseYr with a Date data type.

    Note 

    Each data column name can contain only ten characters and must not have spaces in it. In addition, it cannot contain solely numbers and must contain at least one alphabetical character.

  4. Add a data column for extra information about the CD named Notes with a Char data type.

  5. Add a data column named Scratched. This will contain a true/false value pertaining to whether the CD is scratched, and therefore unplayable. Set its data type as Bool. This will mean that the column can hold only two possible types of data: true or false. Considering that the CD will either be scratched or not scratched, this is very useful for our purposes.

  6. Click the floppy disk icon on the main Rekall window toolbar to save the table. Figure 27-4 shows the columns defined for our table.

    image from book
    Figure 27-4. Add data columns for every piece of data you want to store in your database.

    Note 

    Rekall doesn't automatically save tables, forms or other elements you create, as with Microsoft Access. You must click the Save icon or choose File ® Save every time you make a change.




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net