mysql创建表的时候创建唯一键案例代码如下:
- mysql> create table stu26(
- -> id int auto_increment primary key,
- -> name varchar(20) unique -- 唯一键
- -> );
- Query OK, 0 rows affected (0.05 sec)
复制代码
方法二:
- mysql> create table stu27(
- -> id int primary key,
- -> name varchar(20),
- -> unique(name)
- -> );
- Query OK, 0 rows affected (0.05 sec)
复制代码 多学一招:
unique 或 unique key 是一样的
|
|