开发者

Will ignoring the AUTO_INCREMENT in my table SQL have an effect?

开发者 https://www.devze.com 2023-01-06 14:33 出处:网络
Will ignoring the va开发者_如何学Pythonlue AUTO_INCREMENT in my table SQL have an effect on my current content?No, it won\'t.

Will ignoring the va开发者_如何学Pythonlue AUTO_INCREMENT in my table SQL have an effect on my current content?


No, it won't.

15char


no..it won't effect anything.. AUTO_INCREMENT function is for make array number..it make all data which have been input automatically sequential..and also counting..from 1,2,3,..n..


No, it won't. An AUTO_INCREMENT will keep a counter so that you can INSERT a row without specifying a value for that column.

If you ignore the AUTO_INCREMENT and do explicitly state a value for the column, the counter will be updated. The next insert without explicit value will take the previous insert into account - you don't risk a duplicate value.

Testcase:

Create the table:

CREATE TABLE `counter` (
  `1` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`1`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;

Insert a row, without stating the value:

INSERT INTO `test`.`counter` (`1` ) VALUES (NULL);

There will now be one row, with value 1.

Insert another row, without stating the value:

INSERT INTO `test`.`counter` (`1` ) VALUES (NULL);

There will now be two rows, 1 and 2.

Insert a row while explicitly stating the value:

INSERT INTO `test`.`counter` (`1` ) VALUES ('8');

You will now have three rows, 1, 2, 8

Now insert another row without stating the value:

INSERT INTO `test`.`counter` (`1` ) VALUES (NULL);

The new row will not have value 3 or 4, but the correct value 9:

SELECT * FROM `counter`;

1
2
8
9
0

精彩评论

暂无评论...
验证码 换一张
取 消