Insert value “0″ for primary keys with auto increment in MySQL

In order to insert value 0 in a field that is set as primary key for a MySQL table you need to execute the following query prior to any insert query:

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

Now you can successfully run the insert query with 0 set as value for a primary key, without getting any error message.

About Cristian Radulescu

PHP // MySql // Linux // Android
This entry was posted in MySQL, Programming and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>