如何从mysql表中删除唯一键

发布于 2025-01-03 07:55:48 字数 170 浏览 0 评论 0 原文

我需要从 mysql 表中删除一个唯一键。如何使用 mysql 查询删除它。

我尝试了这个,但它不起作用

alter table tbl_quiz_attempt_master drop unique key;

请帮助我

谢谢

I need to remove a unique key from my mysql table. How can remove that using mysql query.

I tried this but it is not working

alter table tbl_quiz_attempt_master drop unique key;

Please help me

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

自演自醉 2025-01-10 07:55:48

所有键都已命名,您应该使用类似这样的内容 -

ALTER TABLE tbl_quiz_attempt_master
  DROP INDEX index_name;

要删除主键,请使用这个 -

ALTER TABLE tbl_quiz_attempt_master
  DROP INDEX `PRIMARY`;

ALTER TABLE 语法

All keys are named, you should use something like this -

ALTER TABLE tbl_quiz_attempt_master
  DROP INDEX index_name;

To drop primary key use this one -

ALTER TABLE tbl_quiz_attempt_master
  DROP INDEX `PRIMARY`;

ALTER TABLE Syntax.

琴流音 2025-01-10 07:55:48

首先,您需要知道 INDEX 的确切名称(在本例中为唯一键)才能删除或更新它。
索引名称通常与列名称相同。如果一列上应用了多个 INDEX,MySQL 会自动为列名添加编号后缀,以创建唯一的 INDEX 名称。

例如,如果在名为 customer_id 的列上应用 2 个索引,

  1. 第一个索引将被命名为 customer_id 本身。
  2. 第二个索引的名称为 customer_id_2 等等。

了解要删除或更新的索引的名称

SHOW INDEX FROM <table_name>

要按照 @Amr 的建议

要删除索引

ALTER TABLE <table_name> DROP INDEX <index_name>;

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

  1. The first index will be named as customer_id itself.
  2. The second index will be names as customer_id_2 and so on.

To know the name of the index you want to delete or update

SHOW INDEX FROM <table_name>

as suggested by @Amr

To delete an index

ALTER TABLE <table_name> DROP INDEX <index_name>;
懒猫 2025-01-10 07:55:48

以下是如何获取 Devart 的回答或 key_name href="https://stackoverflow.com/questions/9172164/how-to-remove-unique-key-from-mysql-table/9172221#9172221">Uday Sawant的答案:

SHOW INDEX FROM table_name;

这将显示所有给定table_name的索引。您可以选择要删除的索引名称或唯一键。

Here is how to get index_name which is mentioned in Devart's answer or key_name which is mentioned in Uday Sawant's answer:

SHOW INDEX FROM table_name;

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.

时光磨忆 2025-01-10 07:55:48
ALTER TABLE mytable DROP INDEX key_Name;
ALTER TABLE mytable DROP INDEX key_Name;
×纯※雪 2025-01-10 07:55:48

mysql中有两种删除索引的方法二。
第一种方法是 GUI。在这种方法中,您必须打开 MYSQL 的 GUI 界面,然后转到该数据库,然后转到要删除索引的特定表。

之后单击结构选项,然后您可以看到表结构,下面您可以看到表索引。您可以通过单击放置选项来删除索引

在此处输入图像描述

这里的第二种方法

ALTER TABLE student_login_credentials DROP INDEX created_at;

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

enter image description here

Second method by

ALTER TABLE student_login_credentials DROP INDEX created_at;

here student_login_credentials is table name and created_at is column name

海的爱人是光 2025-01-10 07:55:48

要从列中删除唯一键,您必须运行以下查询:

ALTER TABLE your_table_name 
    DROP INDEX tableName_columnName_keyName;

其中 tableName 应该是表的名称,后跟下划线,然后 columnName 应该是要从唯一键约束中删除的列的名称,后跟通过下划线,最后 keyName 应该是键的名称,即在您的情况下是唯一的。

To remove a unique key from a column, you have to run the below query:

ALTER TABLE your_table_name 
    DROP INDEX tableName_columnName_keyName;

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.

江南烟雨〆相思醉 2025-01-10 07:55:48

要添加唯一密钥,请使用:

alter table your_table add UNIQUE(target_column_name);

要删除唯一密钥,请使用:

alter table your_table drop INDEX target_column_name;

To add a unique key use :

alter table your_table add UNIQUE(target_column_name);

To remove a unique key use:

alter table your_table drop INDEX target_column_name;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文