更新时间:2023-01-19 11:47:07
如果要完全编写脚本,可以执行以下操作:
If you want to fully script this, you can do something like this:
SELECT CONCAT('ALTER TABLE ',
table_schema,
'.',
table_name,
' ADD COLUMN id INT AUTO_INCREMENT NOT NULL PRIMARY KEY FIRST;') AS ddl
INTO OUTFILE '/tmp/alter_table.sql'
FROM information_schema.tables
WHERE table_schema = 'db_name'
AND table_type = 'base table';
\. /tmp/alter_table.sql