2

我在一个表中有两个字段(标题,内容),我插入了一些值......:

+--------------------------------------+--------------------------+
| title                                | content                  |
+--------------------------------------+--------------------------+
| hello word                           | this is my first content |
+--------------------------------------+--------------------------+
| smoke Smoking is bad for your health | But i love it            |
+--------------------------------------+--------------------------+

如果我添加一个名为ID的auto_increment字段,则之前输入的值取ID = 0:

+---+--------------------------------------+--------------------------+
|ID | title                                | content                  |
+---+--------------------------------------+--------------------------+
| 0 | hello word                           | this is my first content |
+---+--------------------------------------+--------------------------+
| 0 | smoke Smoking is bad for your health | But i love it            |
+---+--------------------------------------+--------------------------+

我需要这个:

+---+--------------------------------------+--------------------------+
|ID | title                                | content                  |
+---+--------------------------------------+--------------------------+
| 1 | hello word                           | this is my first content |
+---+--------------------------------------+--------------------------+
| 2 | smoke Smoking is bad for your health | But i love it            |
+---+--------------------------------------+--------------------------+

将正确 ID 设置为旧值的唯一方法是 php+foreach?或者我忘记了与 sql/mysql 有什么关系来更快地自动获取正确的 ID 值?

感谢帮助。

4

2 回答 2

2
ALTER TABLE MyTable
ADD ID INT IDENTITY
于 2012-09-09T22:48:19.240 回答
2

好吧,现在是我帮助你的时候了:P。

您将 SQL 代码放在 php 页面或 phpmyadmin 在线代码编辑器中?有时 phpmyadmin 在线编辑器会失败,在您的 php 页面中尝试它,它工作正常。

于 2012-09-09T22:59:42.537 回答