Type.ReplaceTableKeys
Returns a new table type with all keys replaced by the specified list of keys.
Syntax
Type.ReplaceTableKeys(
tableType as type,
keys as list
) as type
Remarks
Returns a new table type with all keys replaced by the specified list of keys.
Each key is defined using a record in the following form:
-
Columns
: a list of the column names that define the key -
Primary
:true
if the key is the table's primary key; otherwise,false
Examples
Example #1
Replace the key information on a table type.
let
BaseType = type table [ID = number, FirstName = text, LastName = text],
KeysAdded = Type.ReplaceTableKeys(
BaseType,
{
[Columns = {"ID"}, Primary = true],
[Columns = {"FirstName", "LastName"}, Primary = false]
}
),
DetailsOfKeys = Type.TableKeys(KeysAdded)
in
DetailsOfKeys
Result:
{
[Columns = {"ID"}, Primary = true],
[Columns = {"FirstName", "LastName"}, Primary = false]
}
Example #2
Clear the key information previously defined on a table type.
let
TypeWithKey = Type.AddTableKey(type table [ID = number, Name = text], {"ID"}, true),
KeyRemoved = Type.ReplaceTableKeys(TypeWithKey, {}),
DetailsOfKeys = Type.TableKeys(KeyRemoved)
in
DetailsOfKeys
Result:
{}
Category
Type