[英]set auto_increment value to old table items
i have in one table two fields (title, content) and i inserted some values...: 我在一个表中有两个字段(标题,内容),并且我插入了一些值...:
+--------------------------------------+--------------------------+
| title | content |
+--------------------------------------+--------------------------+
| hello word | this is my first content |
+--------------------------------------+--------------------------+
| smoke Smoking is bad for your health | But i love it |
+--------------------------------------+--------------------------+
if I add a auto_increment field called ID, the previously input values take ID = 0: 如果我添加一个名为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 |
+---+--------------------------------------+--------------------------+
and i need this: 我需要这个:
+---+--------------------------------------+--------------------------+
|ID | title | content |
+---+--------------------------------------+--------------------------+
| 1 | hello word | this is my first content |
+---+--------------------------------------+--------------------------+
| 2 | smoke Smoking is bad for your health | But i love it |
+---+--------------------------------------+--------------------------+
The only way to set correct ID to old values is php+foreach? 将正确的ID设置为旧值的唯一方法是php + foreach? or i forgot something to do with sql/mysql to takes faster and automatically the correct ID values?
还是我忘记了与sql / mysql的关系,以便更快地自动获取正确的ID值?
Thanks for help. 感谢帮助。
ALTER TABLE MyTable
ADD ID INT IDENTITY
Well,now its my time to help you :P. 好吧,现在是我该为您服务的时间了:
You puts SQL code in a php page or in phpmyadmin online code editor? 您将SQL代码放在php页面或phpmyadmin在线代码编辑器中? Sometimes phpmyadmin online editor fails, try it in your php page and it works fine.
有时phpmyadmin在线编辑器会失败,请在您的php页面中尝试一下,即可正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.