表存在后添加新ID(自动增量)的麻烦

2021-11-30 00:00:00 mysql auto-increment

我有一个包含 38.000 条记录的表,但没有任何像 ID 这样的自动增量列.
现在我必须添加一个ID列,我想知道会不会有麻烦?

I have a table with 38.000 records, but without any auto increment column like ID.
Now I have to add an ID column, and I'm wondering could there be troubles?

推荐答案

您对任何字段的定义更改的问题是更改是破坏性的".最好将这样的更改视为数据迁移.我没有用 MySQL 这样做过,但不得不为 SQL Server 添加自动编号.基本思路是一样的.

You problem with definition change to any field is the change is "destructive". It is best to treat changes like this as a data migration. I have not done this with MySQL, but have had to add auto numbering to SQL Server. The basic idea is the same.

查看文档,因为 MySQL 可能有一种无需重置字段即可添加自动增量的机制.如果是这样,通过 SQL 执行此操作将解决问题.总的来说,我建议不要使用工具直观地进行这些类型的更改,因为大多数工具的方法学具有很强的破坏性.

Check the documentation, as MySQL may have a mechanism for adding aut increment without resetting the field. If so, doing it via SQL will solve the problem. In general, I recommend against doing these types of changes visually, with a tool, as most tools are very destructive in their methdology.

相关文章