Skip to main content

Create a table

Tutorial for creating a table using the JSON DB API

Complete the tutorial setup.

Both the following create table procedures create a table named "athlete". You can use either one.

Note

This procedure must succeed or all other subsequent steps in the tutorial will fail.

Create a table using API Explorer's built-in example

  1. Select the DB API from the Select API dropdown menu.

  2. Select the "createTable - athlete" example from the Templates dropdown menu.

  3. Click Send request (Run Icon).

  4. Verify the action completed successfully.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.

Create a table using code in this tutorial

  1. Paste this code into the API Request editor.

    {
        "api": "db",
        "action": "createTable",
        "params": {
            "databaseName": "ctreeSQL",
            "tableName": "athlete",
            "fields": [
                {
                    "name": "name",
                    "type": "varchar",
                    "length": 30
                },
                {
                    "name": "ranking",
                    "type": "smallint",
                    "nullable": false
                },
                {
                    "name": "birthDate",
                    "type": "date"
                },
                {
                    "name": "playerNumber",
                    "type": "number",
                    "length": 32,
                    "scale": 6
                },
                {
                    "name": "livedPast2000",
                    "type": "bit"
                },
                {
                    "name": "earnings",
                    "type": "money",
                    "length": 32,
                    "scale": 4
                },
                {
                    "name": "favoriteSaying",
                    "type": "varchar",
                    "length": 500
                }
            ]
        },
        "authToken": "clickApplyDefaultsToReplaceThisWithValidAuthToken"
    }
  2. Click Apply defaults to JSON request (Apply) to apply defaults and set the "authToken" to a valid value.

    Note

    You will receive this error if you do not click Apply defaults to JSON request (Apply) to set the "authToken" to a valid session.

    "errorCode": 60031,
        "errorMessage": "Not possible to find valid session for the provided token."
    }
    
  3. Click Send request (Run Icon).

  4. Verify the action completed successfully.

    Note

    "errorCode" with a value of 0 indicates success. "errorCode" with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.