How to add columns and comments to a table in Oracle?
To add a column to a table, you can use the ALTER TABLE statement.
The general syntax for adding a table column is as follows:
ALTER TABLE table_name
ADD column_name data_type;
table_name corresponds to the name of the table where the field needs to be added, column_name is the name of the field to be added, and data_type is the data type of the field.
For example, to add a new field called “salary” to a table named employees with the data type as integer (INT), you can use the following statement:
ALTER TABLE employees
ADD salary INT;
To add comments to table fields, you can use the COMMENT statement. Here is the general syntax for adding comments:
COMMENT ON COLUMN table_name.column_name
IS 'comment';
In which, table_name refers to the name of the table for adding comments, column_name refers to the name of the field for adding comments, and comment is the content of the comment to be added.
For example, to add a comment “employee salary” to the “salary” field in a table named employees, you can use the following statement:
COMMENT ON COLUMN employees.salary
IS '员工薪水';