mysql在建表时,如何能保证除了主键以外的某个键值是唯一的?

来源:百度知道 编辑:UC知道 时间:2024/05/17 08:15:27
我建立了一个表格,有id,md5,context三个项,id为主键。现在我希望md5可以保证是在数据库中无重复项,请问除了将md5设置为主键以外,是否有其他办法?

create table test(
`id` int not null auto_increment,
`md5` char(32) not null,
`content` text,
primary key( `id` ),
unique key( `md5` )
)
engine=myisam default charset=utf8;

create table tablename(
id not null primary key auto_increment,

这样定义的就是唯一的!!