關於修改AUTO_INCREMENT列的預設值的測試

orchidllh發表於2008-04-28

其實是個很簡單的操作,但是忽然有人問我就是想不起來,暫且做個筆記在這裡。

mysql> create table test2(id int(2) AUTO_INCREMENT,name varchar(10),primary key(id));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into test2 values(null,'a'),(null,'b'),(null,'c');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from test2;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
3 rows in set (0.00 sec)

mysql> delete from test2 where id in (2,3);
Query OK, 2 rows affected (0.00 sec)

mysql> select * from test2;
+----+------+
| id | name |
+----+------+
| 1 | a |
+----+------+
1 row in set (0.00 sec)

mysql> insert into test2 values(null,'d');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test2;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 4 | d |
+----+------+
2 rows in set (0.00 sec)

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

mysql> alter table test2 AUTO_INCREMENT=2;
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> insert into test2 values(null,'f');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test2;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | f |
+----+------+
2 rows in set (0.00 sec)

[@more@]

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

相關文章