MySQL Forums
Forum List  »  Microsoft SQL Server

Re: IDENTITY_INSERT in MySql
Posted by: Dmitry Tolpeko
Date: November 30, 2011 03:18AM

Hi Rod,

MySQL allows you inserting identity values explicitly, so you actually do not need IDENTITY_INSERT option, or in other words it is always set in MySQL.

So if INSERT statements contain values for identity (autoincrement), they all will be retained

  CREATE TABLE t_autoinc1
   (
     c1 INT AUTO_INCREMENT PRIMARY KEY
   );

   -- 0 or NULL means that next ID will be generated by MySQL automatically
   
   -- inserts 1
   INSERT INTO t_autoinc1 VALUES (0)
   -- inserts 2
   INSERT INTO t_autoinc1 VALUES (NULL)

   -- inserts 100, not 3
   INSERT INTO t_autoinc1 VALUES (100)

   -- inserts 101
   INSERT INTO t_autoinc1 VALUES (NULL)

More on conversion: http://www.sqlines.com/reference/mysql/statements/tables/auto_increment

Thanks,

Dmitry

Options: ReplyQuote


Subject
Written By
Posted
November 16, 2011 02:38PM
Re: IDENTITY_INSERT in MySql
November 30, 2011 03:18AM
November 30, 2011 09:44AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.