How to add a field and comment in Mysql?
To add a column and its comment to a MySQL table, you can use the ALTER TABLE statement.
- Add field:
ALTER TABLE 表名
ADD 列名 数据类型;
For example, to add an integer type field named “age” in the “users” table, you can execute the following statement:
ALTER TABLE users
ADD age INT;
- Add fields and notes:
ALTER TABLE 表名
ADD 列名 数据类型 COMMENT '备注';
For example, to add an integer type field named “age” in the “users” table and add a comment “user age,” you can execute the following statement:
ALTER TABLE users
ADD age INT COMMENT '用户年龄';
Please note that the added fields will be added at the end of the table. If you need to add a field at a specific position, you can use the AFTER keyword followed by the field name to specify the position. For example:
ALTER TABLE users
ADD email VARCHAR(50) AFTER username;
The above statement will add a VARCHAR(50) type field named “email” after the “username” field.