創建表格時添加:
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;