天天看点

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>