Troubles of adding a new ID (auto increment) after table exist(表存在后添加新ID(自动增量)的麻烦)
问题描述
我有一个包含 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.
这篇关于表存在后添加新ID(自动增量)的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:表存在后添加新ID(自动增量)的麻烦
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
