In sql server there is a something like
IDENTITY_INSERT is set to OFF and we can set in ON after
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
If you delete the row containing the maximum value for an AUTO_INCREMENT column, the value is not reused for a MyISAM or InnoDB table. If you delete all rows in the table with DELETE FROM tbl_name (without a WHERE clause) in autocommit mode, the sequence starts over for all storage engines except InnoDB and MyISAM.
You can use ALTER TABLE to change the auto_increment initial value: ALTER TABLE tbl AUTO_INCREMENT = 5; See the MySQL reference for more details.
In MySQL, the syntax to reset the AUTO_INCREMENT column using the ALTER TABLE statement is: ALTER TABLE table_name AUTO_INCREMENT = value; table_name. The name of the table whose AUTO_INCREMENT column you wish to reset.
A Primary Key just needs to be a unique value that identifies its entry from other entries, and not null. Save this answer. Show activity on this post. Primary key should be unique but not necessarily need to be auto_increment.
I can't imagine any good reason why you need to switch that off.
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);
So why do you need to switch it off?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With