1.设置主键
1)在建表时
在字段后跟 primary key 如create table tb(id int primary key)
create table tb(id int,constraint pkid primary key (id))这种也可以 不过目前不理解什么意思
2)已经建好表且有字段id
alter table tb alter column id int not null
alter table tb add constraint pkid primary key (id)
2.自动编号
String createTable="create table member("
+ "id int(10) unsigned not null auto_increment,"
+ "name varchar(20),"
+ "pass varchar(16),"
+ "primary key(id))";
设置起始值alter table Test auto_increment = 1;