Set AUTO_INCREMENT value programmatically

前端 未结 4 2000
我在风中等你
我在风中等你 2021-01-06 05:20

So this works...

ALTER TABLE variation AUTO_INCREMENT = 10;

But I want to do this;

ALTER TABLE variation AUTO_INCREMENT = (         


        
4条回答
  •  被撕碎了的回忆
    2021-01-06 05:59

    I'm not familiar enough with mysql to give a specific answer. However, in other database engines, there's an EXEC method you can pass a string into that will be executed. You simply write a script that determines the value you want for the auto_increment, then insert that value as a string into the script that is EXEC'd. Basically writing a script that writes a second script and runs it.

    EDIT: Looks like you want a prepared statement. Search for 'Dynamic SQL' There's an almost duplicate here

    EDIT2: Tim, ref this link that is referred to in the almost duplicate StackOverflow post previously given. Search for the string 'Using Parameters' on the page, and you'll get the skinny on that. MySql makes this a little difficult apparently. In MSSqlServer 2000, this was a trivial process. Here is another link to an article about mysql dynamic sql

提交回复
热议问题