保留策略命令retention policy command

本文介绍用于创建和更改保留策略的控制命令。This article describes control commands used for creating and altering retention policy.

显示保留策略Show retention policy

.show <entity_type> <database_or_table> policy retention

.show <entity_type> *  policy retention
  • entity_type:表或数据库entity_type : table or database
  • database_or_tabledatabase_namedatabase_name.table_nametable_name(在数据库上下文中)database_or_table: database_name or database_name.table_name or table_name (in database context)

示例Example

显示名为 MyDatabase 的数据库的保留策略:Show the retention policy for the database named MyDatabase:

.show database MyDatabase policy retention

删除保留策略Delete retention policy

删除数据保留策略可有效地设置无限制的数据保留。Deleting data retention policy is affectively setting unlimited data retention.

如果删除表的数据保留策略,表将从数据库级别派生保留策略。Deleting the table's data retention policy will cause the table to derive the retention policy from the database level.

.delete <entity_type> <database_or_table> policy retention
  • entity_type:表或数据库entity_type : table or database
  • database_or_tabledatabase_namedatabase_name.table_nametable_name(在数据库上下文中)database_or_table: database_name or database_name.table_name or table_name (in database context)

示例Example

删除名为 MyTable1 的表的保留策略:Delete the retention policy for the table named MyTable1:

.delete table MyTable policy retention

更改保留策略Alter retention policy

.alter <entity_type> <database_or_table> policy retention <retention_policy>

.alter tables (<table_name> [, ...]) policy retention <retention_policy>

.alter-merge <entity_type> <database_or_table> policy retention <retention_policy>

.alter-merge <entity_type> <database_or_table_name> policy retention [softdelete = <timespan>] [recoverability = disabled|enabled]
  • entity_type:表或数据库entity_type : table or database
  • database_or_tabledatabase_namedatabase_name.table_nametable_name(在数据库上下文中)database_or_table: database_name or database_name.table_name or table_name (in database context)
  • table_name:数据库上下文中表的名称。table_name : name of a table in a database context. 通配符(此处允许使用 *)。A wildcard (* is allowed here).
  • retention_policy :retention_policy :
    "{ 
        \"SoftDeletePeriod\": \"10.00:00:00\", \"Recoverability\": \"Disabled\"
    }" 

示例Examples

显示名为 MyDatabase 的数据库的保留策略:Show the retention policy for the database named MyDatabase:

.show database MyDatabase policy retention

设置具有 10 天软删除期且禁用数据可恢复性的保留策略:Sets a retention policy with a 10 day soft-delete period and disabled data recoverability:

.alter-merge table Table1 policy retention softdelete = 10d recoverability = disabled

设置具有 10 天软删除期且启用数据可恢复性的保留策略:Sets a retention policy with a 10 day soft-delete period and enabled data recoverability:

.alter table Table1 policy retention "{\"SoftDeletePeriod\": \"10.00:00:00\", \"Recoverability\": \"Enabled\"}"

设置与上述相同的保留策略,但这一次适用于多个表(Table1、Table2 和 Table3):Sets the same retention policy as above, but this time for multiple tables (Table1, Table2 and Table3):

.alter tables (Table1, Table2, Table3) policy retention "{\"SoftDeletePeriod\": \"10.00:00:00\", \"Recoverability\": \"Enabled\"}"

设置使用默认值的保留策略:软删除期为 100 年并启用可恢复性:Sets a retention policy with the default values: 100 years as the soft-delete period and recoverability enabled:

.alter table Table1 policy retention "{}"