我有一個表中的兩個字段(標題,內容),我插入一些值...:設置AUTO_INCREMENT值,以舊錶項
+--------------------------------------+--------------------------+
| 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設置爲舊的值的唯一方法是對HP +的foreach?或者我忘記了與sql/mysql做更快,並自動正確的ID值?
感謝您的幫助。
您是否在使用類似phpMyAdmin的內容將此字段ID添加到auto_increment中?或者你如何添加這個領域? – dbf
@dbf我嘗試了2種方法(phpmyadmin和代碼)。我的代碼: ALTER TABLE'blog' ADD'id' INT(255)NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST –