[MySQL Tips]:如何删除unique key约束
【场景】:
假设最初创建了一个表bank,在street属性上添加了unique约束。
create table branch(
branch_name char(30) not null primary key,
city varchar(20),
street varchar(20) unique
);
表结构如下:

【问题】
后来发现在同一个street上可以出现多个支行,也就是说street不应该是unique的。此时怎样删除unique约束呢?
【方法】
alter table branch drop index street;
【备注】
1. 上述表达式中index street,即为索引名称,指代unique key。

2. 添加属性约束的方法
alter table [table_name] add constraint [constraint_name] [unique| primary key|foreign key] ([column_name])
![]() |
作者:Double_Win 出处: http://www.cnblogs.com/double-win/p/3903184.html 声明: 由于本人水平有限,文章在表述和代码方面如有不妥之处,欢迎批评指正~ |
[MySQL Tips]:如何删除unique key约束的更多相关文章
- mySQL中删除unique key的语法 (删除某个字段的唯一性)
mySQL中删除unique key的语法 CREATE TABLE `good_booked` ( `auto_id` int(10) NOT NULL auto_increment, `goo ...
- mySQL中删除unique key的语法
CREATE TABLE `good_booked` ( `auto_id` int(10) NOT NULL auto_increment, `good_id` int(11) default ...
- postgresql数据库primary key约束/not null约束/unique约束及default值的添加与删除、列的新增/删除/重命名/数据类型的更改
如果在建表时没有加primary key约束.not null约束.unique约束.default值,而是创建完表之后在某个字段添加的话 1.primary key约束的添加与删除 给red_pac ...
- Mysql增加、删除和修改列属性和约束,和一些有用的查询语句
最近在整理关于MySql的东西,把一些需要记录的东西写下来,以便以后查询和浏览,以下是一些操作技巧.添加表字段alter table` 表名称` add transactor varchar(10) ...
- 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY
[转载]http://blog.csdn.net/w87875251l/article/details/7929657 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY ...
- mysql 中UNIQUE KEY 到底是约束还是索引?
答案来自:https://zhidao.baidu.com/question/1863373387452612907.html 两者关系 unique索引包含了unique约束,因为unique约束是 ...
- MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
参考:MySQL中KEY.PRIMARY KEY.UNIQUE KEY.INDEX 的区别 对于题目中提出的问题,可以拆分来一步步解决.在 MySQL 中 KEY 和 INDEX 是同义.那这个问题就 ...
- unique key 唯一约束
#添加唯一约束mysql> alter table tb2 -> add unique key(name) ->;#删除唯一约束mysql> alter table ...
- mysql中key 、primary key 、unique key 与index区别
一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id ) NOT NULL auto_increment, ) default NU ...
随机推荐
- Java8 Stream语法详解 2
1. Stream初体验 我们先来看看Java里面是怎么定义Stream的: A sequence of elements supporting sequential and parallel agg ...
- springboot分环境打包(maven动态选择环境)
分环境打包核心点:spring.profiles.active pom.xml中添加: <profiles> <profile> <id>dev</id> ...
- e.g.-basic-Si
! Band structure of silicon. The points listed after plot1d below are the ! vertices joined in the b ...
- Python staticmethod() 函数
Python staticmethod() 函数 Python 内置函数 python staticmethod 返回函数的静态方法. 该方法不强制要求传递参数,如下声明一个静态方法: class ...
- docker在centos和Ubuntu的安装
CentOS: http://blog.csdn.net/wuapeng/article/details/51728614 rpm -Uvh http://www.elrepo.org/elrepo- ...
- async与await
在方法上可以加 async,方法体内需要有 await,没有await的话,会出现warn警告.async单独出现是没有用的. await只能出现在Task前面.await Task的后面的代码会被封 ...
- 深入了解 php 底层机制 (-)洪定坤
- Java数据结构和算法(二)树的基本操作
Java数据结构和算法(二)树的基本操作 数据结构与算法目录(https://www.cnblogs.com/binarylei/p/10115867.html) 一.树的遍历 二叉树遍历分为:前序遍 ...
- 深入浅出 JMS(三) - ActiveMQ 消息传输
深入浅出 JMS(三) - ActiveMQ 消息传输 一.消息协商器(Message Broker) broke:消息的交换器,就是对消息进行管理的容器.ActiveMQ 可以创建多个 Broker ...
- windows10 装linux子系统
http://blog.csdn.net/Yuxin_Liu/article/details/52347898 试了一下,下载太慢,就没继续用,可以用实验楼这个网来玩玩linux
