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

2023-07-17数据库问题
0

本文介绍了表存在后添加新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(自动增量)的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14