当前位置:网站首页>MySQL constraint_ Unique constraint
MySQL constraint_ Unique constraint
2022-07-22 17:27:00 【Camellia——】
-- Unique constraint :unique( Restricted fields can only be unique , Can't repeat )
-- Usually in non business fields (id only )
CREATE TABLE stu(
id INT,
NAME VARCHAR(20),
phone_number VARCHAR(11) UNIQUE -- Unique constraint
);
-- Insert
INSERT INTO stu(id,NAME,phone_number)VALUES(1,' Zhang San ',133);
INSERT INTO stu(id,NAME,phone_number)VALUES(2,' Li Si ',133); -- Duplicate entry '133' for key 'phone_number'
DELETE FROM stu WHERE id=2;
DELETE FROM stu WHERE id=1;
-- Delete unique constraint
-- alter table Table name drop index The field name of the unique constraint
-- alter table stu modify phone_number varchar(11);// It is equivalent to changing only one fieldALTER TABLE stu DROP INDEX phone_number;
-- Add unique constraints ( Ensure that there is no duplicate data before adding a unique constraint )
ALTER TABLE stu MODIFY phone_number VARCHAR(11) UNIQUE;SELECT*FROM stu
边栏推荐
- CASTOR 通过 Polygonica 3D引擎实现云端大型装配进行高吞吐量分析,HOOPS Exchange助力其实现对 CAD 数据文件读取
- Qianxin joined the Euler open source community to jointly promote the application of commercial passwords
- 重装Win11系统如何在线一键进行?
- 【图文并茂】在线一键重装win7系统详细教程
- Castor realizes high-throughput analysis of large-scale cloud assembly through polygonica 3D engine, and hoops exchange helps it read CAD data files
- [C language interesting experiment]
- Win11遇到问题需要重启怎么办?
- Matlab function: filtfilter -- zero phase digital filtering
- 【机器学习】pytorch如何加载自定义数据集并进行数据集划分
- DOF depth of field Foundation
猜你喜欢
牛客网刷题1【最小步数Fibonacci数列】
"New capabilities" of rongyun Super Group
Write a sequencer plug-in sequence subtitle (1)
Go语言学习日记【三十一】golang与pgsql交互
UART通信实验(查询方式)
Take it. The strongest "high concurrency" system design 46 consecutive questions, killing a crowd of interviewers every minute
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
线程和进程
Qianxin joined the Euler open source community to jointly promote the application of commercial passwords
Realization of a springboard machine
随机推荐
微信营销策略,微信营销的优势是什么?
An annotation implementation method writes the returned data to the cache (facet, redis Implementation)
LCD笔记(2)Framebuffer驱动程序框架
会议OA项目
Abaqus实现二自由度振动系统模态计算
Pytorch deep learning practice-b station Liu erden-day1
PostgreSQL判断是否为空coalesce
Information security CISP certification - what are your concerns?
Realization of a springboard machine
Breadth first search
怎么使用js实现计算器和计时器功能
Spark高级特性,220720,
李宏毅机器学习2020--P20&21 RNN
电子信息工程专业毕设题目选题推荐
What is I18N and what is its function
重装Win11系统如何在线一键进行?
JS的DOM操作——阻止事件冒泡和阻止默认事件
NPM warn config global ` --global `, `--local` are deprecated Use `--location=global` instead.
LVS load balancing cluster
【外部排序】归并思想完成外部排序