如何从mysql表中删除唯一键
我需要从 mysql 表中删除一个唯一键。如何使用 mysql 查询删除它。
我尝试了这个,但它不起作用
alter table tbl_quiz_attempt_master drop unique key;
请帮助我
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
所有键都已命名,您应该使用类似这样的内容 -
要删除主键,请使用这个 -
ALTER TABLE 语法。
All keys are named, you should use something like this -
To drop primary key use this one -
ALTER TABLE Syntax.
首先,您需要知道 INDEX 的确切名称(在本例中为唯一键)才能删除或更新它。
索引名称通常与列名称相同。如果一列上应用了多个 INDEX,MySQL 会自动为列名添加编号后缀,以创建唯一的 INDEX 名称。
例如,如果在名为
customer_id
的列上应用 2 个索引,customer_id
本身。customer_id_2
等等。了解要删除或更新的索引的名称
要按照 @Amr 的建议
要删除索引
First you need to know the exact name of the INDEX (Unique key in this case) to delete or update it.
INDEX names are usually same as column names. In case of more than one INDEX applied on a column, MySQL automatically suffixes numbering to the column names to create unique INDEX names.
For example if 2 indexes are applied on a column named
customer_id
customer_id
itself.customer_id_2
and so on.To know the name of the index you want to delete or update
as suggested by @Amr
To delete an index
以下是如何获取 Devart 的回答或 key_name href="https://stackoverflow.com/questions/9172164/how-to-remove-unique-key-from-mysql-table/9172221#9172221">Uday Sawant的答案:
这将显示所有给定
table_name
的索引。您可以选择要删除的索引名称或唯一键。Here is how to get
index_name
which is mentioned in Devart's answer orkey_name
which is mentioned in Uday Sawant's answer:This will show all the indexes for the given
table_name
. And you can pick the name of the index or the unique key you want to remove.mysql中有两种删除索引的方法二。
第一种方法是 GUI。在这种方法中,您必须打开 MYSQL 的 GUI 界面,然后转到该数据库,然后转到要删除索引的特定表。
之后单击结构选项,然后您可以看到表结构,下面您可以看到表索引。您可以通过单击放置选项来删除索引
这里的第二种方法
Student_login_credentials 是表名,created_at 是列名
There are two method two remove index in mysql.
First method is GUI. In this method you have to open GUI interface of MYSQL and then go to that database and then go to that particular table in which you want to remove index.
After that click on the structure option, Then you can see table structure and below you can see table indexes. You can remove indexes by clicking on drop option
Second method by
here student_login_credentials is table name and created_at is column name
唯一键实际上是一个索引。
http://codeghar.wordpress.com/2008/ 03/28/drop-unique-constraint-in-mysql/
Unique key is actually an index.
http://codeghar.wordpress.com/2008/03/28/drop-unique-constraint-in-mysql/
要从列中删除唯一键,您必须运行以下查询:
其中 tableName 应该是表的名称,后跟下划线,然后 columnName 应该是要从唯一键约束中删除的列的名称,后跟通过下划线,最后 keyName 应该是键的名称,即在您的情况下是唯一的。
To remove a unique key from a column, you have to run the below query:
Where tableName should be your name of the table followed by an underscore then columnName should be the name of the column which you want to remove from the unique key constraint followed by an underscore and at last keyName should be the name of the key i.e unique in your case.
要添加唯一密钥,请使用:
要删除唯一密钥,请使用:
To add a unique key use :
To remove a unique key use: