MySQL在存储过程中禁用auto_increment列临时

uma*_*hod 4 mysql

在SQL Server中有类似的东西

IDENTITY_INSERT设置为OFF,之后我们可以设置为ON

我想知道的是,在mysql中类似的东西我需要临时设置并设置为ON,例如

create procedure ()

    begin   
      IDENTITY_INSERT is set to OFF
      Some insert statement
      Some insert statement
      IDENTITY_INSERT is set to ON 
    end
Run Code Online (Sandbox Code Playgroud)

Ale*_*lex 5

我无法想象有什么理由需要关闭此功能。

如果您需要在自定义中插入任何记录,id AUTO_INCREMENT则没有障碍。

http://sqlfiddle.com/#!9/4d413/1

CREATE TABLE t1 (id int NOT NULL AUTO_INCREMENT, PRIMARY KEY (id));

INSERT INTO t1 VALUES (23);
INSERT INTO t1 VALUES (null);
Run Code Online (Sandbox Code Playgroud)

那么,为什么需要将其关闭?