【场景】:

假设最初创建了一个表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约束的更多相关文章

  1. mySQL中删除unique key的语法 (删除某个字段的唯一性)

    mySQL中删除unique key的语法 CREATE TABLE `good_booked` (  `auto_id` int(10) NOT NULL auto_increment,  `goo ...

  2. mySQL中删除unique key的语法

    CREATE TABLE `good_booked` (  `auto_id` int(10) NOT NULL auto_increment,  `good_id` int(11) default ...

  3. postgresql数据库primary key约束/not null约束/unique约束及default值的添加与删除、列的新增/删除/重命名/数据类型的更改

    如果在建表时没有加primary key约束.not null约束.unique约束.default值,而是创建完表之后在某个字段添加的话 1.primary key约束的添加与删除 给red_pac ...

  4. Mysql增加、删除和修改列属性和约束,和一些有用的查询语句

    最近在整理关于MySql的东西,把一些需要记录的东西写下来,以便以后查询和浏览,以下是一些操作技巧.添加表字段alter table` 表名称` add transactor varchar(10) ...

  5. 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY

    [转载]http://blog.csdn.net/w87875251l/article/details/7929657 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY ...

  6. mysql 中UNIQUE KEY 到底是约束还是索引?

    答案来自:https://zhidao.baidu.com/question/1863373387452612907.html 两者关系 unique索引包含了unique约束,因为unique约束是 ...

  7. MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别

    参考:MySQL中KEY.PRIMARY KEY.UNIQUE KEY.INDEX 的区别 对于题目中提出的问题,可以拆分来一步步解决.在 MySQL 中 KEY 和 INDEX 是同义.那这个问题就 ...

  8. unique key 唯一约束

    #添加唯一约束mysql> alter table tb2    -> add unique key(name)   ->;#删除唯一约束mysql> alter table ...

  9. mysql中key 、primary key 、unique key 与index区别

    一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id ) NOT NULL auto_increment, ) default NU ...

随机推荐

  1. python3 django连接mysql,同步表结构

    第一步:安装PyMySQ代替MySQLdb pip3 install PyMySQL 然后在工程目录的__init__.py中填写下面两句话   import pymysql pymysql.inst ...

  2. Javascript读写CSS属性

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  3. ios 8 联系人ABPeoplePickerNavigationController

    一. ios 联系人ABPeoplePickerNavigationControllerDelegate方法,新添加下面两个联系人选中方法,适配iOS8需要实现 // Called after a p ...

  4. 6-Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法

    Qt给父widget加上styleSheet(添加背景图)而不改变子widget的styleSheet的方法 比如用stylesheet给widget加背景图,可以用qt designer修改ui文件 ...

  5. linux-redhat-git源码安装

    1.查看是否已安装git,如果存在自带的git,则卸载 查看git版本 $ git --version 删除自带git $ yum remove git 2.安装依赖包 $ yum -y instal ...

  6. linux下常用文件操作命令

    1.find命令 按内容查找文件 find /home/vpopmail/domains/best-21ixi.jp/bounce/Maildir/new/ -name "*" | ...

  7. Codeforces 612B. Wet Shark and Bishops 模拟

    B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  8. NET(C#)连接各类数据库-集锦

    1.C#连接连接Access程序代码:------------------------------------------------------------------------------- u ...

  9. python之零碎知识

    一 join方法 主要是做字符串的拼接:join后面跟的类型必须是要可迭代得到对象 for循环的对象是可迭代对象 # result = "".join(li) # print(re ...

  10. 551. Student Attendance Record I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...