天天看點

9、mysql中auto_increment的簡單使用

1、auto_increment的複位

ALTER TABLE your_table_name AUTO_INCREMENT = 1

2、The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows。示例:

CREATE TABLE animals (

     id MEDIUMINT NOT NULL AUTO_INCREMENT,

     name CHAR(30) NOT NULL,

     PRIMARY KEY (id)

) ENGINE=MyISAM;

INSERT INTO animals (name) VALUES

    ('dog'),('cat'),('penguin'),

    ('lax'),('whale'),('ostrich');

3、No value was specified for the AUTO_INCREMENT column, so MySQL assigned sequence numbers automatically. You can also explicitly assign NULL or 0 to the column to generate sequence numbers.

參考

【1】 關于auto_increment的一個應用讨論

<a href="http://www.iteye.com/topic/198779">http://www.iteye.com/topic/198779</a>

【2】 mysql官網

<a href="http://www.w3school.com.cn/sql/sql_datatypes.asp">http://www.w3school.com.cn/sql/sql_datatypes.asp</a>

<a href="http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html">http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html</a>

<a href="http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-type-overview">http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-type-overview</a>

【3】 使用auto_increment經驗總結

<a href="http://www.frostsky.com/2011/04/mysql-auto_increment-2/">http://www.frostsky.com/2011/04/mysql-auto_increment-2/</a>

【4】 總結的不錯

<a href="http://www.bhcode.net/article/20090219/4161.html">http://www.bhcode.net/article/20090219/4161.html</a>