当前位置:网站首页>mysql约束之_唯一约束
mysql约束之_唯一约束
2022-07-22 06:00:00 【Camellia——】
-- 唯一约束:unique(限制字段只能唯一,不能重复)
-- 一般是在非业务字段(id唯一)
CREATE TABLE stu(
id INT,
NAME VARCHAR(20),
phone_number VARCHAR(11) UNIQUE -- 唯一约束
);
-- 插入
INSERT INTO stu(id,NAME,phone_number)VALUES(1,'张三',133);
INSERT INTO stu(id,NAME,phone_number)VALUES(2,'李四',133); -- Duplicate entry '133' for key 'phone_number'
DELETE FROM stu WHERE id=2;
DELETE FROM stu WHERE id=1;
-- 删除唯一约束
-- alter table 表名 drop index 唯一约束所在的字段名臣
-- alter table stu modify phone_number varchar(11);//相当于只改了个字段ALTER TABLE stu DROP INDEX phone_number;
-- 添加唯一约束(添加唯一约束之前保证不能出现重复的数据)
ALTER TABLE stu MODIFY phone_number VARCHAR(11) UNIQUE;SELECT*FROM stu
边栏推荐
- How to download and install xshell plus6
- Lepton 无损压缩原理及性能分析
- Application of workflow engine in vivo marketing automation | engine 03
- MATLAB函数:filtfilt——零相位数字滤波
- @The difference between resource and @autowired
- Make good use of these seven tips in code review, and it is easy to establish your opposition alliance
- [machine learning] how pytorch loads custom datasets and divides them
- vivo官网APP全机型UI适配方案
- UE4 combines the objects made by the brush into a whole
- STL map
猜你喜欢
Pytoch deep learning practice lesson 11 (CNN)
【矩阵乘法】外部矩阵乘法
Spark advanced features, 220720,
浅谈不可转让的声誉积分NFT SBTs面临的困境
Qt5.9.2 initial import using msvc2017_ 64 record of problems encountered by compiler
MySQL中的日志“binlog”的三种格式这么好玩
14 multithread 1
怎么使用js实现计算器和计时器功能
The aboveboard water stickers come from people's perception of summer vacation
分支语句和循环语句
随机推荐
浅谈不可转让的声誉积分NFT SBTs面临的困境
UE4 set night (update skysphere according to directionallight direction)
[machine learning] how pytorch loads custom datasets and divides them
【LeetCode】814. 二叉树剪枝
Atomicinteger class is used in multithreading to ensure thread safety
牛客网 Fibonacci数列
14-多线程1
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
Qt5.9.2 initial import using msvc2017_ 64 record of problems encountered by compiler
Xshell Plus6下载及安装使用的方法
UE4 build terrain with grayscale map
服務器buffer/cache 的產生原因和釋放buffer/cache
GMT 0009-2012 data format go language operation
牛客网 替换空格
NVIDIA hardware architecture
vivo官网APP全机型UI适配方案
从0到1建设智能灰度数据体系:以vivo游戏中心为例
STL resize容量规律集合
The most detailed conversion of Base64, blob and file
一文带你了解redux的工作流程——action/reducer/store