Create the database table

Where you are

>   Create the database table

   Define extended attribute information

   Add data to the table

To create the database table, you:

  • Define the columns in the table

  • Define a primary key

  • Enter comments to document the table

  • Save the table

Define the columns in the table

  1. Click the Database button in the PowerBar.

    The Database painter workspace displays. It contains many views for working with database information. If your workspace does not look like this, you may want to select View>Layouts>(Default).

  2. Position the pointer on the Tables folder in the PB Demo DB V2017 IM database and select New Table from the pop-up menu.

    The view in which you define the columns in the table displays. The cursor is in the Column Name box for the first column.

  3. Type id and press Tab.

    The cursor moves to the Data Type box. The default datatype (char) is highlighted. The datatype for the id column needs to be integer.

    About default datatypes

    Char is the default datatype for the first column. The default datatype for subsequent columns is the type of the previous column.

  4. Click the arrow to the right of the word char and select integer from the drop-down list of available datatypes.

    This changes the datatype.

  5. Press Tab three times.

    This moves you past the setting of No for the column labeled Null. No means you do not want to allow the column you are defining to be empty (to have a null value). Since you always want a value for id, you leave the value No. You also move past the column labeled Default. You are not going to specify a default.

  6. Type last_name and press Tab.

    The cursor moves to the Type column. The most recently used datatype (integer) is highlighted. The last_name column should be type char, so you change the datatype.

  7. Type c and press Tab.

    Typing c is a shortcut for choosing char quickly. The cursor moves to the Width column.

  8. Type 15.

    This allows 15 characters for the last name instead of 10.

  9. Press Tab three times.

    This moves you past the setting of No for the column labeled Null to the Name box for the next column. No is what you want (name cannot be empty). You move past the column labeled Default again.

  10. Finish entering information about the table columns.

The following table shows all the values needed to define the columns in the contact table. You have already entered values for the first two columns (id and last_name).

Name

Type

Width

Dec

Null

Default

id

integer

 

 

No

(None)

last_name

char

15

 

No

(None)

first_name

char

15

 

No

(None)

title

char

2

 

No

(None)

street

char

30

 

No

(None)

city

char

20

 

No

(None)

state

char

2

 

No

(None)

zip

char

5

 

No

(None)

phone

char

10

 

Yes

(None)

fax

char

10

 

Yes

(None)


When you have finished, the Columns view should look like this.

Save the table

You have now entered all of the column information needed. Now you finish creating the table.

  1. Select File>Save from the menu bar.

    The Create New Table dialog box displays.

    You leave the owner as dba (database administrator) and enter a name for the table.

  2. Type contact1 in the Table Name box.

    Click OK.

    InfoMaker passes the SQL needed to create the table to the SQL Anywhere DBMS, which creates the table.

    InfoMaker displays a representation of the table in the Database painter Object Layout view.

    The list of columns displays. The scroll bar on the right side means that there are more columns than can be displayed at once. To see the other columns, you can click the down arrow at the bottom of the scroll bar.

Define a primary key

A primary key uniquely identifies each row. In your contact table, id is the unique identifier of each row of data.

  1. Select Object>Insert>Primary Key from the menu bar. (If the menu item is grayed out, click the Object Layout view to make it current and then select the menu item from the menu bar.)

    The Primary Key property sheet displays in the Object Details view. Here you can pick one or more columns as the primary key.

  2. Click id in the list of columns.

  3. Select File>Save from the menu bar.

    This defines id as the primary key for your table. Notice that the representation of the table now includes a symbol for the primary key of the table.

Next you define a comment for the table.

Enter comments to document the table

Although not required, comments can be helpful in identifying tables.

  1. Position the pointer on the title bar of the representation of the contact1 table, display the pop-up menu, and select Properties.

    The Table Properties property sheet displays in the Object Details view.

  2. Click in the Comments box and type This is the sample table for the tutorial created by [your name].

    This associates the comments with the table you are creating.

  3. Select File>Save from the menu bar.