myisam對於update,insert,delete關於auto_incremant的影響

psufnxk2000發表於2015-12-09
myisam對於update,insert,delete關於auto_incremant的影響:
mysql> create table inc_myisam (id int auto_increment primary key,name varchar(10)) engine=myisam;
Query OK, 0 rows affected (0.00 sec)


mysql> insert into inc_myisam (name) values ('name1');
Query OK, 1 row affected (0.00 sec)


mysql> insert into inc_myisam (name) values ('name22');
Query OK, 1 row affected (0.01 sec)


mysql> show create table inc_myisam;
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table      | Create Table                                                                                                                                                                      |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| inc_myisam | CREATE TABLE `inc_myisam` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> insert into inc_myisam values (4,'name4');
Query OK, 1 row affected (0.00 sec)


mysql> select * from inc_myisam;
+----+--------+
| id | name   |
+----+--------+
|  1 | name1  |
|  2 | name22 |
|  4 | name4  |
+----+--------+
3 rows in set (0.00 sec)


mysql> show create table inc_myisam;
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table      | Create Table                                                                                                                                                                      |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| inc_myisam | CREATE TABLE `inc_myisam` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> update inc_myisam set id=10 where id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> show create table inc_myisam;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table      | Create Table                                                                                                                                                                       |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| inc_myisam | CREATE TABLE `inc_myisam` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> delete from inc_myisam where id=10;
Query OK, 1 row affected (0.00 sec)


mysql> show create table inc_myisam;
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table      | Create Table                                                                                                                                                                       |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| inc_myisam | CREATE TABLE `inc_myisam` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 |
+------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


對於myisam來說,update,insert來說 都會把 AUTO_INCREMENT的值升上去,
但是delete不會把AUTO_INCREMENT的值降下去。


轉載請註明源出處 
QQ 273002188 歡迎一起學習 
QQ 群 236941212 
oracle,mysql,mongo 相互交流

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25099483/viewspace-1869360/,如需轉載,請註明出處,否則將追究法律責任。

相關文章