Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Database Administration » SQL Anywhere database connections » Tutorial: Creating a SQL Anywhere database

 

Lesson 2: Adding tables to the database

Create tables to store the information in your database.

Prérequis

This lesson assumes that you have completed all preceding lessons. See Lesson 1: Creating a database file.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Creating a SQL Anywhere database.

 Task
  1. Start the Create Table Wizard. In the left pane of Sybase Central, right-click Tables and click New » Table.

    1. In the What do you want to name the new table field, type Products.

    2. Click Finish.

    The database server creates the table using defaults, and then displays the Columns tab in the right pane. The Name field for the new column is selected and you are prompted to specify a name for the new column.

  2. Type ProductID as the name for the new column.

    Since this is the first column in the table, PKey is selected, indicating that the column is the primary key for the table.

  3. In the Data Type list, click Integer.

  4. Click the ... button.

  5. Click the Value tab and click Default value » System-defined » autoincrement.

    An AUTOINCREMENT value increments for each row added to the table. This value ensures that values in the column are unique—a requirement for primary keys.

  6. Click OK.

  7. Click File » New » Column.

    1. In the Name field, type ProductName.

    2. In the Data Type list, click Char.

    3. In the Size list, click 15.

  8. Repeat the previous steps to add the following tables to your database:

    • Customers table   Add a table named Customers with the following columns:

      • CustomerID   The identification number of each customer. Ensure that PKey is selected, set the Data Type to Integer, and set the Default value to autoincrement.

      • CompanyName   The name of each company. Set the DataType to Char with a maximum length of 35 characters.

    • SalesOrders table   Add a table named SalesOrders with the following columns:

      • SalesOrderID   The identification number of each sales order. Ensure that PKey is selected, set the Data Type to Integer, and set the Default value to autoincrement.

      • OrderDate   The date on which the order was placed. Set the DataType to Date.

      • CustomerID   The identification number of the customer who placed the sales order. Set the DataType to Integer.

    • SalesOrderItems table   Add a table named SalesOrderItems with the following columns:

      • SalesOrderItemsID   The identification number of the sales order that the item belongs to. Ensure that PKey is selected and set the Data Type to Integer.

      • LineID   The identification number of each sales order. Ensure that PKey is selected and set the Data Type to Integer.

        Since PKey is set for both SalesOrderItemsID and LineID, the primary key for the table comprises the concatenated values of these two columns.

      • ProductID   The identification number of the product being ordered. Set the DataType to Integer.

  9. Click File » Save.

Résultat

You have created four tables for your database.

 See also