-- unique的使用
CREATE TABLE t19
(id INT UNIQUE, -- 表示id列是不可以重复的
`name` VARCHAR(32),
email VARCHAR(32)
);
INSERT INTO t19
VALUES(1,'jack','jack@sohu.com');
INSERT INTO t19
VALUES(1,'tom','tom@sohu.com'); -- 【报错】
如果没有指定not null,则unique 字段可以有多个null
-- unique使用细节
-- 如果没有指定not null,则unique 字段可以有多个null
INSERT INTO t19
VALUES(NULL,'tom','tom@sohu.com');
SELECT * FROM t19;
一张表可以有多个unique 字段
-- 一张表可以有多个unique 字段
CREATE TABLE t20
(id INT UNIQUE, -- 表示id列是不可以重复的
`name` VARCHAR(32) UNIQUE, -- -- 表示name列是不可以重复的
email VARCHAR(32)
);
DESC t20