Lesson 2: Add tables to the database

Use the following procedure to create a table named Products.

 To create a table
  1. In the right pane of Sybase Central, double-click Tables.

  2. Right-click Tables and choose New » Table.

  3. In the What Do You Want To Name The New Table field, type Products.

  4. 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 a prompt waits for you to specify a name for the new column.

  5. 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.

    When creating a table, you can create a primary key that is made up of more than one columns by creating the columns and placing a checkmark in each PKey column. See Primary keys.

  6. In the Data Type list, select Integer.

  7. Click the ellipsis (three dots) button.

  8. Click the Value tab and choose Default Value » System-Defined » Autoincrement.

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

  9. Click OK.

  10. From the File menu, choose New » Column.

  11. Complete the following fields:

    • In the Name field, type ProductName.
    • In the Data Type list, select Char.
    • In the Size list, select 15.
  12. Add the following tables to your database.

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

      • CustomersID   An identification number for each customer. Make sure 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:

      • SalesOrdersID   An identification number for each sales order. Set the DataType to Integer, and make sure PKey is selected. 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 of which the item is a part. Set the DataType to Integer, and make sure PKey is selected.

      • LineID   An identification number for each sales order. Set the DataType to Integer, and make sure PKey is selected.

        Note

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

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

  13. From the File menu, choose Save.

 See also