Modify Column Comment
Function
Modify the column comment of a non-partitioned table or a partitioned table. Spark 4.0 recommends using the ALTER COLUMN syntax and is also compatible with the CHANGE COLUMN syntax.
Syntax
- Syntax 1 (recommended, Spark 4.0):
ALTER TABLE [db_name.]table_name ALTER COLUMN col_name COMMENT 'col_comment';
- Syntax 2 (compatible):
ALTER TABLE [db_name.]table_name CHANGE COLUMN col_name col_name col_type COMMENT 'col_comment';
Keywords
- ALTER COLUMN: Modify column properties (recommended syntax for Spark 4.0).
- CHANGE COLUMN: Modify column (compatible syntax, requires specifying both column name and type).
- COMMENT: Describe columns.
Parameters
| Parameter | Mandatory | Description |
|---|---|---|
| db_name | No | Database name. Only letters, digits, and underscores (_) are allowed. It cannot be purely numeric and cannot start with an underscore. |
| table_name | Yes | Table name. |
| col_name | Yes | Column field name. Must be an existing column. |
| col_type | Mandatory only for CHANGE COLUMN syntax | Column data type. The CHANGE COLUMN syntax does not support modifying the column data type. Specify the data type used when creating the table. The ALTER COLUMN syntax does not require this. |
| col_comment | Yes | Modified column comment. The comment content is a valid string with a length not exceeding 1,024 bytes. |
Precautions
- Spark 4.0 recommends using the ALTER COLUMN syntax to modify column comments. This syntax is more concise and does not require repeatedly specifying the column data type.
- The CHANGE COLUMN syntax is a compatible syntax. When using it, you must specify the same column data type as when the table was created.
Example 1: Modify Comment Using ALTER COLUMN (Recommended)
Use the ALTER COLUMN syntax recommended by Spark 4.0 to modify the comment of column c1 in table t1.
ALTER TABLE t1 ALTER COLUMN c1 COMMENT 'the new comment';
Example 2: Modify Comment Using CHANGE COLUMN (Compatible)
ALTER TABLE t1 CHANGE COLUMN c1 c1 STRING COMMENT 'the new comment';
Example 3: Modify Column Comment in a Specified Database
Modify the comment of the name column in the employee table of database mydb.
ALTER TABLE mydb.employee ALTER COLUMN name COMMENT 'Employee name';
Example 4: Modify Comments for Multiple Columns
Modify the comments for multiple columns in table t1 separately.
ALTER TABLE t1 ALTER COLUMN c1 COMMENT 'Description for column 1'; ALTER TABLE t1 ALTER COLUMN c2 COMMENT 'Description for column 2';
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot