首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MySQL 增添唯一约束

2012-07-03 
MySQL 添加唯一约束创建表时直接设置:DROP TABLE IF EXISTS `student`CREATE TABLE `student` (? `stu_id

MySQL 添加唯一约束

创建表时直接设置:

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);

热点排行