惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News Blog

博客园 - 星朝

博客园搬家 窗口函数详细用法 JVM启动参数大全 BigDecimal.setScale用法总结 - 星朝 - 博客园 springboot项目上传文件出现临时文件目录为空 springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件 java获取本机IP Java获取本机ip和服务器ip Spring中的@Transactional(rollbackFor = Exception.class)属性详解 注解@CrossOrigin解决跨域问题 unique key index区别 MySQL中添加唯一约束和联合唯一约束 移动IM开源框架Tigase > Openfire > Ejabberd对比分析 Tigase 8.0开发环境搭建 Tigase手动安装过程 几个时序数据库 时序数据库入门 MySQL执行计划extra中的using index 和 using where using index 的区别 ETL的详细解释定义
mysql 创建唯一约束表
星朝 · 2020-01-14 · via 博客园 - 星朝

说明:

    UNIQUE 约束唯一标识数据库表中的每条记录。

    UNIQUE 和 PRIMARY KEY 约束均为列或列集合提供了唯一性的保证。

    PRIMARY KEY 拥有自动定义的 UNIQUE 约束。

 请注意,每个表可以有多个 UNIQUE 约束,但是每个表只能有一个 PRIMARY KEY 约束。


1、创建一个测试表:

create table test(
    id int unsigned auto_increment,
    name varchar(50) not null,
    age int unsigned,
    unique(name),
    primary key(id)
)engine=innodb charset=utf8

2、插入数据测试

    insert into test(name,age) values('张三',21)
查询
    

再添加相同name名称的数据会报错添加不上

原文地址:https://blog.csdn.net/weirdo_world/article/details/100115290