MySQL在存储过程中禁用auto_increment列临时 [英] Mysql disable auto_increment column temporary in Stored procedure

查看:144
本文介绍了MySQL在存储过程中禁用auto_increment列临时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql server中,类似

In sql server there is a something like

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

IDENTITY_INSERT is set to OFF and we can set in ON after

我想知道的是在mysql中类似的东西,我需要暂时关闭并设置为开,例如

I wanna know is that something similar in mysql where i need to temporary set off and set ON i.e like

create procedure ()

    begin   
      IDENTITY_INSERT is set to OFF
      Some insert statement
      Some insert statement
      IDENTITY_INSERT is set to ON 
    end

推荐答案

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

I can't imagine any good reason why you need to switch that off.

如果您需要使用自定义id AUTO_INCREMENT插入任何记录,则不是障碍.

If you need to insert any record with your custom id AUTO_INCREMENT is not a barrier.

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);

那为什么要关闭它?

这篇关于MySQL在存储过程中禁用auto_increment列临时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆