您的位置:首页 > 数据库 > MySQL

MySQL添加数据库的唯一索引的几种方式~

2016-07-15 10:44 411 查看
创建表时直接设置:

DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`stu_id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`stu_id`),
UNIQUE KEY `UK_student_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

创建唯一索引:

create unique index UK_student_name on student (name);

建表后添加约束:

alter table student add constraint uk_student_name unique (name);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: