Create a Table
/mobile/system/databaseManagement/tables
Creates a table.
Note: When you use the Database Access operations to work with the table data, you'll need to know the order of the primary keys that you used when you created (or re-created) the table. However, when you call either GET /mobile/system/databaseManagement/tables
or GET /mobile/system/databaseManagement/tables/{table}
, the primaryKeys
property lists the columns in alphabetical order, and not in the order that you used when you created or re-created the table. Therefore, you must make a note of the order when you create or re-create a table.
Permissions
Only team members with the Mobile_DbMgmt
role can access the Database Management API. You can use this operation only when the environment's Database_CreateTablesPolicy
is set to allow
or explicitOnly
.
Request
- application/json
-
Oracle-Mobile-Extra-Fields(optional): string
Comma-separated list that specifies which extra columns to include from amongst
id
,createdBy
,createdOn
,modifiedBy
, andmodifiedOn
. If there are no extra columns specifynone
. Theid
column is added to the table only when no primary key is specified.When you use the Database Access API's
/objects
resource, these columns are updated automatically when records are inserted and updated. The user does not need to provide values for these columns.
object
-
columns:
array columns
Minimum Number of Items:
0
The database table columns. -
name:
string
The table name. This attribute is case sensitive. There are database restrictions on the maximum length of the name and which special characters are allowed. However, because the names are within double quotation marks, you can use spaces and some special characters.
-
primaryKeys:
array primaryKeys
Minimum Number of Items:
0
The columns to use for the primary keys. Note that when you use the Database Access operations to work with the table data, you'll need to know the order of the primary keys that you used when you created (or re-created) the table. However, when you call either `GET /mobile/system/databaseManagement/tables` or `GET /mobile/system/databaseManagement/tables/{table}`, the `primaryKeys` property lists the columns in alphabetical order, and not in the order that you used when you created or re-created the table. Therefore, you must make a note of the order when you create or re-create a table. -
requiredColumns(optional):
array requiredColumns
Minimum Number of Items:
0
The columns that must be set with non-null values. These columns are created with the `NOT NULL` constraint.
array
0
-
Array of:
object columnInfo
Database column metadata.
array
0
array
0
object
-
name:
string
The column name.
-
size(optional):
integer
For `string`, `integer`, and `decimal` columns, the size or precision of the column. String values can't exceed 4000 characters. Unless you have a valid business constraint, you should not specify size and subsize for integers and decimals because this limits which values are acceptable and makes it hard to resize the column. When possible, allow the database to size and store the value as efficiently as possible.
-
subSize(optional):
integer
For `decimal` columns, the scale of the column, meaning the number of places after the decimal point.
-
type:
Allowed Values:
[ "string", "dateTime", "integer", "decimal", "boolean" ]
The column type. `dateTime` is a string in ISO date and time format (for example, `2015-03-21T17:00:00.000-08:00`).
{
"name":"Movies",
"requiredColumns":[
"title",
"releaseDate"
],
"columns":[
{
"name":"title",
"type":"string",
"size":50
},
{
"name":"synopsis",
"type":"string",
"size":200
},
{
"name":"inTheaters",
"type":"boolean"
},
{
"name":"releaseDate",
"type":"dateTime"
},
{
"name":"runningTime",
"type":"integer"
},
{
"name":"totalGross",
"subSize":2,
"type":"decimal",
"size":10
}
],
"primaryKeys":[
"title"
]
}
Response
- application/json
200 Response
The table was created successfully.
object
-
object tableInfo
Database table metadata
-
object tableInfoRead-allOf[1]
object
-
columns:
array columns
Minimum Number of Items:
0
The database table columns. -
name:
string
The table name. This attribute is case sensitive. There are database restrictions on the maximum length of the name and which special characters are allowed. However, because the names are within double quotation marks, you can use spaces and some special characters.
-
primaryKeys:
array primaryKeys
Minimum Number of Items:
0
The columns to use for the primary keys. Note that when you use the Database Access operations to work with the table data, you'll need to know the order of the primary keys that you used when you created (or re-created) the table. However, when you call either `GET /mobile/system/databaseManagement/tables` or `GET /mobile/system/databaseManagement/tables/{table}`, the `primaryKeys` property lists the columns in alphabetical order, and not in the order that you used when you created or re-created the table. Therefore, you must make a note of the order when you create or re-create a table. -
requiredColumns(optional):
array requiredColumns
Minimum Number of Items:
0
The columns that must be set with non-null values. These columns are created with the `NOT NULL` constraint.
object
-
indexes(optional):
array indexes
Minimum Number of Items:
0
The database table indexes.
array
0
-
Array of:
object columnInfo
Database column metadata.
array
0
array
0
object
-
name:
string
The column name.
-
size(optional):
integer
For `string`, `integer`, and `decimal` columns, the size or precision of the column. String values can't exceed 4000 characters. Unless you have a valid business constraint, you should not specify size and subsize for integers and decimals because this limits which values are acceptable and makes it hard to resize the column. When possible, allow the database to size and store the value as efficiently as possible.
-
subSize(optional):
integer
For `decimal` columns, the scale of the column, meaning the number of places after the decimal point.
-
type:
Allowed Values:
[ "string", "dateTime", "integer", "decimal", "boolean" ]
The column type. `dateTime` is a string in ISO date and time format (for example, `2015-03-21T17:00:00.000-08:00`).
array
0
-
Array of:
object index
The table index metadata.
object
-
columns:
array indexColumns
Minimum Number of Items:
1
Unique Items Required:true
The indexed columns. -
name:
string
The index name.
array
1
true
Examples
The following example shows how to create a database table by submitting a POST request on the REST resource using cURL. For more information about cURL, see Use cURL.
curl -i
-X POST
-u username:password
-d @tables.json
-H "Content-Type: application/json; charset=utf-8"
-H "Oracle-Mobile-Extra-Fields: createdOn"
-H "Oracle-Mobile-Backend-ID: ABCD9278-091f-41aa-9cb2-184bd0586fce"
https://fif.cloud.oracle.com/mobile/system/databaseManagement/tables
Example of Request Body
The following shows an example of the request body. This example creates a table name Movies
. Its primary key is title
. Only title
and releaseDate
are required.
{
"name": "Movies",
"primaryKeys": [
"title"
],
"requiredColumns": [
"title",
"releaseDate"
],
"columns": [
{
"name": "title",
"size": 50,
"type": "string"
},
{
"name": "synopsis",
"size": 4000,
"type": "string"
},
{
"name": "inTheaters",
"type": "boolean"
},
{
"name": "releaseDate",
"type": "dateTime"
},
{
"name": "runningTime",
"size": 3,
"type": "integer"
},
{
"name": "poster",
"type": "binary"
},
{
"name": "totalGross",
"size": 10,
"subSize": 2,
"type": "decimal"
},
{
"name": "createdBy",
"size": 80,
"type": "string"
},
{
"name": "createdOn",
"type": "dateTime"
},
{
"name": "modifiedBy",
"size": 80,
"type": "string"
},
{
"name": "modifiedOn",
"type": "dateTime"
}
],
"indexes": [
{
"name": "Movies_pk",
"columns": [
"title"
]
}
]
}
Example of Response Header
The following shows an example of the response header:
200 OK Content-Type: application/json Date: Mon, 29 Jan 2017 20:32:51 GMT
Example of Response Body
The following example shows, in JSON format, the contents of the response body, which lists the metadata for the database table. Notice the createdOn
column. This was added to the table as a result of including the Oracle-Mobile-Extra-Fields: createdOn
header in the request.
{
"name": "Movies",
"primaryKeys": [
"title"
],
"requiredColumns": [
"title",
"releaseDate"
],
"columns": [
{
"name": "title",
"size": 50,
"type": "string"
},
{
"name": "synopsis",
"type": "string"
},
{
"name": "inTheaters",
"type": "boolean"
},
{
"name": "releaseDate",
"type": "dateTime"
},
{
"name": "runningTime",
"size": 3,
"type": "integer"
},
{
"name": "poster",
"type": "binary"
},
{
"name": "totalGross",
"size": 10,
"subSize": 2,
"type": "decimal"
},
{
"name": "createdOn",
"type": "dateTime"
}
]
}