Creating custom tables

There are two applications related to custom tables in Kentico:

  • Custom tables application allows you to create new custom tables, given you possess the global administrator privilege level. You can also view and manipulate data in existing tables using this interface.
  • Custom table data application allows you to view and manipulate data in existing custom tables only.

Note that you can create new custom tables using the wizard in the Custom tables application only. There is currently no simple way of creating custom tables using the API. This is due to the need to create related objects and settings — these tasks are handled by the wizard.

Creating a custom table

Follow the example to create a new custom table using the New custom table wizard.

Starting the New custom table wizard

  1. Open the Custom tables application.
  2. Click New custom table. A New custom table wizard starts.

Step 1

  1. Enter the following details:
    • Custom table display name: People
      • display name is used in Kentico user interface.
    • Namespace: customtable
    • Name: people
      • Name is used in website code — always preceded by a Namespace, which allows you to have different tables of the same name in different contexts.
  2. Click Next.

Entering the details of the new custom table

Step 2

Specify the details of the database table that the custom table uses.

  1. Choose Create a new database table.

  2. Leave the value customtable_People in the Database table name field.

    Available options

    • Create a new database table - choose this option to create a brand new table in the system’s database.
      • Database table name - the actual name of the table in the system database. A name in the <namespace><code name>_ format is pre-filled automatically.
      • Primary key name - primary key column name, pre-filled with the ItemID value.

     

    • Use an existing database table - choose this option if you already have a physical table in the system database and want to register it in the system.
      • Database table name - the actual name of the table in the system database. The drop-down list offers only database tables which are not part of the default Kentico database schema and are not yet registered for any object.
      • Primary key name - primary key column name. The original table’s primary key column is used automatically. Note that this column needs to be an identity column as well.

     

    The following check-boxes allow you to choose the default fields that you want to include in the custom table:

    • Include ItemGUID field - globally unique ID of the particular custom table data record. Note that this field is mandatory if you want to stage the table’s data to a different instance of Kentico.
    • Include ItemCreatedBy field - user name of the user who created the item.
    • Include ItemCreatedWhen field - date and time of when the item was created.
    • Include ItemModifiedBy field - user name of the user who last modified the item.
    • Include ItemModifiedWhen field - date and time of last modification.
    • Include ItemOrder field - order of the item when table content list is displayed. The lower number, the earlier position in the list.
  3. Make sure all the checkboxes are enabled.

  4. Click Next.

Specifying the details of the database table

Step 3

Third step contains a field editor. The field editor lets you define the columns in the database table.

Create the following fields to follow this example:

  1. Create a field using the New field button with the following properties:

    • Field name: FirstName
    • Data type: Text
    • Size: 100
    • Required: Yes (check the box)
    • Field caption: First name
    • Form control: Text box
  2. Click Save.

  3. Create a second field using New field with the following properties:

    • Field name: LastName
    • Data type: Text
    • Size: 100
    • Required: Yes (check the box)
    • Field caption: Last name
    • Form control: Text box
  4. Click Save.

  5. Create a third field using New field with the following properties:

    • Field name: DateOfBirth
    • Data type: Date
    • Required: No (leave the box unchecked)
    • Field caption: Date of birth
    • Form control: Calendar
    • Editing control settings -> Edit time: No
    • Editing control settings -> Show ‘Now’ link: No
  6. Click Save.

  7. Click Next.

Creating fields for the custom table

Step 4

Select for which sites you want to make the custom table available

  1. Click Add sites. A dialog box opens.
  2. Choose Corporate Site (or any site that you want to add the custom table to).
  3. Click Next.

Step 5

The last step gives you an overview of the tasks executed by the wizard.

Finish the wizard. The system redirects you to the General tab of the custom table that you created.