For example, in table: user field: userid name pw, The useid of the user table is not auto-incrementing. Change userid to auto-increment. Run the following statement to add userid auto-increment by 1 each time. Statement: alter table 'user' change userid int not null auto_increment primary key; table SQL:
Create table 'user '(
'Username' varchar (20) not null,
'PW 'varchar (20) not null,
'Userid' int (11) not null AUTO_INCREMENT,
Primary key ('userid ')
) ENGINE = InnoDB default charset = utf8;
Extended knowledge: // ADD a field and set the primary key alter table tabelname ADD new_field_id int (5) unsigned default 0 not null auto_increment, ADD primary key (new_field_id ); // ADD the index alter table tablename ADD primary key (id); // ADD the index www.bkjia.com alter table tablename CHANGE depno int (5) not null; alter table tablename add index name (field name 1 [, field name 2…]); Alter table tablename add index emp_name (name); // ADD the index alter table tablename add unique emp_name2 (cardnumber) with UNIQUE restrictions; // delete an index alter table tablename drop index emp_name; // ADD a field: alter table table_name ADD field_name field_type; // Delete the field alter table table_name DROP field_name; // rename the alter table table_name CHANGE field_name1 field_name2 integer; // adjust the field order alter table 'users' CHANGE 'user _ password' varchar (20) not null after user_name; // alter table table_name CHANGE field_name bigint not null; alter table infos CHANGE list tinyint not null default '0'; // modify the original field name and type: www.bkjia.com alter table table_name CHANGE old_field_name new_field_name field_type; // rename the alter table table_name rename new_table_name; // cascade update and delete (red, Case Insensitive) drop table if exists 'mail _ model'; create TABLE mail_model (id varchar (50) primary key not null, mail_filename varchar (200), content varchar (2000 )) ENGINE = InnoDB default charset = gbk; drop table if exists 'mail _ model_extend '; create TABLE mail_model_extend (id int (6) auto_increment not null primary key, rid varchar (50) not null, content varchar (2000), INDEX (RID), foreign key (RID) REFERENCES mail_model (ID) on delete cascade on update cascade) ENGINE = InnoDB default charset = gbk;