How to AUTOINCREMENT starting from a certain number/offset?

只谈情不闲聊 提交于 2019-12-04 06:31:40

问题


I am running an fgetcsv query to import a bunch of data from a CSV into WordPress.

I am wondering how I can start an auto increment from a certain number, for example, from 1000 onwards.

$import1="INSERT into wp_postmeta (meta_id,post_id,meta_key,meta_value) values(',',',','first_name','$data[1]')";

This is an example of the code. the meta_id should use a normal auto increment, but the post_id I want to start from a certain number.

How would I accomplish this?


回答1:


To set the starting value for an auto increment field, you can use alter table

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;

As far as I know, it is not possible to have two auto incrementing fields on the same table in mysql, so you have to do it progamatically yourself (eg with a trigger)




回答2:


To change the AUTO_INCREMENT value on the table:

ALTER TABLE wp_postmeta AUTO_INCREMENT = 1000;


来源:https://stackoverflow.com/questions/14467577/how-to-autoincrement-starting-from-a-certain-number-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!