.alter table.alter table

.alter table 命令:The .alter table command:

  • 保护“已保留”列中的数据Secures data in "preserved" columns
  • 对表列重新排序Reorders table columns
  • 对现有表设置新列架构 docstring 和文件夹,并覆盖现有列架构 docstring 和文件夹Sets a new column schema, docstring, and folder to an existing table, overwriting the existing column schema, docstring, and folder
  • 必须在指定表名范围的特定数据库的上下文中运行Must run in the context of a specific database that scopes the table name
  • 需要表管理员权限Requires Table Admin permission


.alter 命令使用不当可能会导致数据丢失。Using the .alter command incorrectly may lead to data loss.


.alter 有一个对应的 .alter-merge 表命令,它具有类似的功能。The .alter has a counterpart, the .alter-merge table command that has similar functionality. 有关详细信息,请参阅 .alter-merge tableFor more information, see .alter-merge table


.alter table TableName (columnName:columnType, ...) [with ([docstring = Documentation] [, folder = FolderName] )].alter table TableName (columnName:columnType, ...) [with ([docstring = Documentation] [, folder = FolderName] )]

  • 表将具有采用指定的顺序的完全相同的列。The table will have exactly the same columns, in the same order, as specified. 指定表列:Specify the table columns:
  • 如果未在命令中指定现有列,则将删除这些列,且列中的数据将丢失,如使用 .drop column 命令时一样。If existing columns aren't specified in the command, they'll be dropped and data in them will be lost, like with the .drop column command.
  • 更改表时,不支持更改列类型。When you alter a table, altering a column type isn't supported. 请改用 .alter column 命令。Use the .alter column command instead.


更改之前,请使用 .show table [TableName] cslschema 获取现有列架构。Use .show table [TableName] cslschema to get the existing column schema before you alter it.

此命令将如何影响数据?How will the command affect the data?

  • 该命令实际上不修改现有数据。Existing data isn't physically modified by the command. 已删除的列中的数据会被忽略。Data in removed columns is ignored. 新列中的数据被假定为 null。Data in new columns is assumed to be null.
  • 根据群集的配置方式,即使没有用户交互,数据引入也可能会修改表的列架构。Depending on how the cluster is configured, data ingestion might modify the table's column schema, even without user interaction. 更改表的列架构时,请确保引入操作不会添加命令随后要删除的必需列。When you make changes to a table's column schema, ensure that ingestion won't add needed columns that the command will then remove.


如果将数据引入表的过程会修改表的列架构,且与 .alter table 命令并行发生,那么执行这些过程时可能不知道表列的顺序。Data ingestion processes into the table that modify the table's column schema, and that occur in parallel with the .alter table command, might be performed agnostic to the order of table columns. 这也有可能会将数据引入到错误的列中。There is also a risk that data will be ingested into the wrong columns. 请通过在命令期间停止引入操作,或者确保此类引入操作始终使用映射对象来避免这些问题。Prevent these issues by stopping ingestion during the command, or by making sure that such ingestion operations always use a mapping object.


.alter table MyTable (ColumnX:string, ColumnY:int) 
.alter table MyTable (ColumnX:string, ColumnY:int) with (docstring = "Some documentation", folder = "Folder1")