Does TiDB support adding multiple columns in a single "alter table add column" statement?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB支持在一个alter table add column增加多个字段么

| username: 数据源的TiDB学习之路

[Test Environment for TiDB] Testing
[TiDB Version] v7.5.1
[Reproduction Path] What operations were performed to encounter the issue
mysql> alter table test322 add column d varchar(10),e varchar(10);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 46 near “e varchar(10)”
mysql> alter table test322 add column d varchar(10) e varchar(10);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 46 near “e varchar(10)”
[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration] Enter TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots/Logs/Monitoring]

| username: 像风一样的男子 | Original post link

Try running: ALTER TABLE test322 ADD COLUMN (d VARCHAR(10), e VARCHAR(10));

| username: 数据源的TiDB学习之路 | Original post link

I referred to MySQL, and the following syntax can be executed:
alter table test322 add column d varchar(10), add column e varchar(10);

| username: 数据源的TiDB学习之路 | Original post link

Well, I tried it, and your syntax works too.

alter table test322 add column (f varchar(10), g varchar(10));
| username: 像风一样的男子 | Original post link

Another way is:

ALTER TABLE test322 ADD COLUMN d VARCHAR(10), ADD COLUMN e VARCHAR(10);
| username: 数据源的TiDB学习之路 | Original post link

Yes, thank you very much.

| username: 这里介绍不了我 | Original post link

Learned.

| username: 随缘天空 | Original post link

Similar to MySQL syntax.

| username: linnana | Original post link

Mostly compatible
image

| username: YuchongXU | Original post link

Support for this feature

| username: TiDBer_ok0VXN1s | Original post link

Are there any libraries that are not supported…?

| username: GreenGuan | Original post link

Version 7.5.1 supports adding multiple columns in a single statement, but version 5 does not.

| username: zhaokede | Original post link

Usually, to save time, I use Navicat to add and control the position of new fields directly in the interface.

| username: 啦啦啦啦啦 | Original post link

Your syntax is incorrect. MySQL doesn’t support this usage either. The new version of TiDB supports adding multiple columns in a single statement. Using the general syntax alter table ... add xxx, add xxx will definitely work.

| username: DBAER | Original post link

Support it

| username: 数据源的TiDB学习之路 | Original post link

There will be an error when adding 2 fields simultaneously in Navicat. It seems that there is a compatibility issue between the tool and the database.

| username: 数据源的TiDB学习之路 | Original post link

The official TiDB documentation should also include the syntax for adding multiple columns.

| username: changpeng75 | Original post link

The syntax diagram in the documentation is very clear. AddColumnSpec can be repeated, separated by commas.

| username: zhanggame1 | Original post link

In Navicat, adding two fields at the same time will result in an error, mainly because of the use of “after”. Multiple “after” statements depend on columns that have not yet been added. Modifying the automatically generated SQL will allow it to execute.

| username: TIDB-Learner | Original post link

The syntax of MySQL is almost supported.