.execute database script.execute database script

在单个数据库作用域内批量执行控制命令。Executes batch of control commands in scope of a single database.

语法Syntax

.execute database script.execute database script
[with ( PropertyName = PropertyValue [, ...] )] [with ( PropertyName = PropertyValue [, ...] )]
<|
Control-commands-scriptControl-commands-script

parametersParameters

  • Control-commands-script :包含一个或多个控制命令的文本。Control-commands-script : Text with one or more control commands.
  • 数据库作用域 :脚本应用于作为请求上下文一部分指定的“数据库作用域”。Database scope : Script is applied on the database scope specified as part of the request context.

可选属性Optional properties

属性Property 类型Type 说明Description
ContinueOnErrors bool 如果设置为 false,脚本将在发生第一个错误时停止。If set to false - the script will stop on the first error. 如果设置为 true,脚本将继续执行。If set to true - the script execution continues. 默认:falseDefault: false.

输出Output

脚本中显示的每个命令在输出表中都显示为一条单独记录。Each command appearing in the script will be reported as a separate record in the output table. 每个记录都具有以下字段:Each record has the following fields:

输出参数Output parameter 类型Type 说明Description
OperationIdOperationId GuidGuid 命令的标识符。Identifier of the command.
CommandTypeCommandType StringString 命令的类型。The type of the command.
CommandTextCommandText StringString 特定命令的文本。Text of the specific command.
结果Result StringString 特定命令执行的结果。Outcome of the specific command execution.
ReasonReason StringString 有关命令执行结果的详细信息。Detailed information about command execution outcome.

备注

  • 脚本文本可能包括命令之间的空行和注释。The script text may include empty lines and comments between the commands.
  • 命令按它们在输入脚本中出现的顺序依次执行。Commands are executed sequentially, in the order they appear in the input script.
  • 脚本执行是非事务性的,出错时不执行回滚。Script execution is non-transactional, and no rollback is performed upon error. 建议在使用 .execute database script 时使用幂等形式的命令。It's advised to use the idempotent form of commands when using .execute database script.
  • 命令的默认行为 - 在第一个错误处失败,可以使用属性参数对其进行更改。Default behavior of the command - fail on the first error, it can be changed using property argument.
  • 不执行只读控制命令(.show 命令),并报告状态 SkippedRead-only control commands (.show commands) aren't executed and are reported with status Skipped.

示例Example

.execute database script <|
//
// Create tables
.create-merge table T(a:string, b:string)
//
// Apply policies
.alter-merge table T policy retention softdelete = 10d 
//
// Create functions
.create-or-alter function
  with (skipvalidation = "true") 
  SampleT1(myLimit: long) { 
    T1 | limit myLimit
}
OperationIdOperationId CommandTypeCommandType CommandTextCommandText 结果Result ReasonReason
1d28531b-58c8-4023-a5d3-16fa73c06cfa1d28531b-58c8-4023-a5d3-16fa73c06cfa TableCreateTableCreate .create-merge table T(a:string, b:string).create-merge table T(a:string, b:string) 已完成Completed
67d0ea69-baa4-419a-93d3-234c0383436067d0ea69-baa4-419a-93d3-234c03834360 RetentionPolicyAlterRetentionPolicyAlter .alter-merge table T policy retention softdelete = 10d.alter-merge table T policy retention softdelete = 10d 已完成Completed
0b0e8769-d4e8-4ff9-adae-071e52a650c70b0e8769-d4e8-4ff9-adae-071e52a650c7 FunctionCreateOrAlterFunctionCreateOrAlter .create-or-alter function.create-or-alter function
with (skipvalidation = "true")with (skipvalidation = "true")
SampleT1(myLimit: long) {SampleT1(myLimit: long) {
T1 | limit myLimitT1 | limit myLimit
}}
已完成Completed