Add Columns
Function
Adds one or more new columns to a table.
Syntax
ALTER TABLE [db_name.]table_name ADD COLUMNS (col_name1 col_type1 [COMMENT col_comment1], ...);
Keywords
- ADD COLUMNS: Adds columns.
- 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. |
| col_type | Yes | Column field type. |
| col_comment | No | Column description. Only string constants are supported. |
Precautions
This SQL statement is not recommended for concurrent execution. In concurrent scenarios, the results of adding columns may overwrite each other.
Example 1: Add a Single Column
Add an INT type column age to table t1.
ALTER TABLE t1 ADD COLUMNS (age INT);
Example 2: Add Multiple Columns
Add two columns, column2 and column3, to table t1 simultaneously.
ALTER TABLE t1 ADD COLUMNS (column2 INT, column3 STRING);
Example 3: Add a Column with a Comment
Add a STRING type column address to table t1 with a column comment.
ALTER TABLE t1 ADD COLUMNS (address STRING COMMENT 'User address information');
Example 4: Add a Column to a Table in a Specified Database
Add a column salary to the table employee in database mydb.
ALTER TABLE mydb.employee ADD COLUMNS (salary DECIMAL(10,2) COMMENT 'Employee salary');
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