MySQL Key值(PRI, UNI, MUL)怎样设置?

MySQL Key值(PRI, UNI, MUL)怎样设置?,第1张

PRI primary key 表示主键,唯一写法: id bigint(20) unsigned primary key not null ,

uni UNIQUE 表示唯一 写法 id bigint(20) unsigned UNIQUE default NULL

mul 添加了索引 写法: alter table test add index suoyin (col_name1)

如果有同时存在,

显示顺序 PRI>UNI>MUL

你这样设置之后,是不能插入的空(NULL),而是能插入空串(\\'\\')。

如果不让插入空串,应该使用check,例如:

CREATE TABLE table2 (

title varchar(50) NOT NULL,

message varchar(200) NOT NULL DEFAULT \\'内容\\',

msname varchar(50) NOT NULL DEFAULT \\'发布人\\',

date date NOT NULL,

PRIMARY KEY (`title`) ,

CHECK (title!=\\'\\')

)

PRI primary key 表示主键,唯一写法: id bigint(20) unsigned primary key not null ,

uni UNIQUE 表示唯一 写法 id bigint(20) unsigned UNIQUE default NULL

mul 添加了索引 写法: alter table test add index suoyin (col_name1)

如果有同时存在,

显示顺序 PRI>UNI>MUL


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/10886925.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-12
下一篇 2023-05-12

发表评论

登录后才能评论

评论列表(0条)

保存