I have created a table and In table i have a column "city" , i did the type of column as Unique ,but now i don't need it as unique . i want to edit it because i want to insert the same name of city but i couldnt do it.
Error Code: 1062. Duplicate entry 'istanbul' for key 'ilAdı'
I tried to change it from here but i get this error.
"
Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE hotel.müşteriler
;
ALTER TABLE hotel.müşteriler ALTER INDEX ilAdı VISIBLE;
ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INDEX ilAdı VISIBLE' at line 1
SQL Statement:
ALTER TABLE hotel.müşteriler ALTER INDEX ilAdı VISIBLE "
You can write the query for removing the unique key from the column like this:
alter table "your table name" drop index "the name of the column";
the quotations are not need.
this will remove the unique key from the column.
Related
I created this using MySQL WorkBench
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC);
ALTER TABLE `android_marketplace`.`ban_utilizator`
ADD CONSTRAINT `ban_utilizator_id_utilizator`
FOREIGN KEY (`id_utilizator`)
REFERENCES `android_marketplace`.`utilizatori` (`id_utilizator`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
I am getting this :
Operation failed: There was an error while applying the SQL script to the
database.
Executing:
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC);
ALTER TABLE `android_marketplace`.`ban_utilizator`
ADD CONSTRAINT `ban_utilizator_id_utilizator`
FOREIGN KEY (`id_utilizator`)
REFERENCES `android_marketplace`.`utilizatori` (`id_utilizator`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
ERROR 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC)' at line 2
SQL Statement:
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC)
The error has nothing to do with a foreign key.
You must name the index you want to drop.
Syntax error messages include the context of the problem. If the syntax error says:
check ... for the right syntax to use near '
ADD INDEX ban_utilizator_id_utilizator_idx (id_utilizator ASC)'
This means the syntax was expecting to find something else at the point where you provided ADD INDEX.
In this case, it was expecting a name for the index you tried to drop in the clause immediately preceding ADD INDEX.
I have tried both the syntaxes:
Alter Table bc DROP FOREIGN KEY STUD_ID;
It is giving the error: Can't DROP 'STUD_ID'; check that column/key exists
Alter Table bc DROP CONSTRAINT STUD_ID;
It is giving the error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT STUD_ID' at line 1
Suggest me the possible ways.
ALTER TABLE TableName DROP FOREIGN KEY ForeignKeyConstraintName;
hope this helps :)
Your first query works. It is telling you that there is no such key to drop. This means your key has another name. It has not the same name as the column it indexes. Run
show index from bc
to show all key names and then run your query again with the correct name
Alter Table bc DROP FOREIGN KEY <STUD_ID_index_name>
alter table bc drop foreign key forconstraintname
I created a table and assigned a UNIQUE CONSTRAINT to a specific column.
... column_name INT UNSIGNED NOT NULL UNQUE
Now I no longer want the column to have the unique constraint, and so I tried modifying that:
ALTER TABLE mytable DROP INDEX column_name
like I saw here.
The above query executes successfully the first time. But when I try inserting duplicate values in the column_name column, I still get the error
#1062 Duplicate entry '10' for key column_name_2
Which, I presume, means the Constraint still remains on the table. (Also funny how _2 gets appended to the column name). But if I repeat the above ALTER statement, I get
#1091 - Can't DROP 'column_name'; check that column/key exists
I also tried
ALTER TABLE mytable DROP INDEX UNIQUE
and it gives me the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNIQUE' at line 1
Don't know if I'm missing something, but how do I remove the UNIQUE constraint from this column?
The issue came up because I had earlier ran the following query, in trying to remove the UNIQUE constraint.:
ALTER TABLE mytable CHANGE column_name column_name INT UNSIGNED NOT NULL
This somehow created a new column called column_name_2 and assigned it the UNIQUE constraint. So when I ran SHOW CREATE TABLE like #Paolof76 suggested, I found among the columns:
UNIQUE KEY `column_name_2` (`column_name`)
which i presume got created due to the ALTER statement above.
So I ran
ALTER TABLE mytable DROP INDEX column_name_2
which eliminated the unique key and solved my problem.
Thanks for the heads-up #Paolof76!
I am trying to run the query:
ALTER IGNORE TABLE test_table DROP PRIMARY KEY, ADD PRIMARY KEY(id);
test_table is just a temporary table I'm using for testing purposes, and id is a column in it.
The query works fine without the "IGNORE" key word, but when I add it I get the error message:
"Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IGNORE TABLE test_table ADD PRIMARY KEY(id)' at line 1"
How do I fix this? Or how can I run that query and ignore any errors that might occur? Thanks!
As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error. Please check your version
I have created a database with two tables user and userdiary.
In the "user" table I have id and email fields.
In the "userdiary" table I have a field called email. I want to link this field with the one in the "user" table.
I'm using phpmyAdmin to add sql statements.
I tried doing ALTER TABLE userdiary FOREIGN KEY (email) REFERENCES user(email)
but I get the error #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (email) REFERENCES user(email)' at line 1
I looked at many forums but could not find a solution to this issue.
It will be great if any of you could help me resolve this issue.
Thanks.
You are missing the keyword add:
ALTER TABLE userdiary ADD FOREIGN KEY (email) REFERENCES user(email)
----------------------^