Type.ReplaceTableKeys
语法
Type.ReplaceTableKeys(tableType as type, keys as list) as type
关于
返回一个新的表类型,其中所有键都替换为指定的键列表。
每个键是使用以下形式的记录定义的:
Columns
:用于定义键的列名的列表Primary
:如果键是表的主键,则为true
;否则为false
验证指定的键列表,以确保定义的主键不超过一个,并且所有键列名都存在于表类型中。
示例 1
替换有关表类型的键信息。
使用情况
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
输出
{
[Columns = {"ID"}, Primary = true],
[Columns = {"FirstName", "LastName"}, Primary = false]
}
示例 2
清除先前在表类型中定义的键信息。
使用情况
let
TypeWithKey = Type.AddTableKey(type table [ID = number, Name = text], {"ID"}, true),
KeyRemoved = Type.ReplaceTableKeys(TypeWithKey, {}),
DetailsOfKeys = Type.TableKeys(KeyRemoved)
in
DetailsOfKeys
输出
{}