创建表格时添加:
create table table1(id int auto_increment primary key,...)
alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key.
创建表格时添加:
CREATE TABLE `orders` ( `order_num` int(11) NOT NULL auto_increment, `order_date` datetime NOT NULL, `cust_id` int(11) NOT NULL, PRIMARY KEY (`order_num`), KEY `fk_orders_customers` (`cust_id`), CONSTRAINT `fk_orders_customers` FOREIGN KEY (`cust_id`) REFERENCES `customers` (`cust_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;
创建表格后添加:
alter table users AUTO_INCREMENT=10000;
alter table users AUTO_INCREMENT=123456;
原文地址:http://blog.csdn.net/hehaoyang666/article/details/41281113