can't drop index because its name is an integer - mysql

I have some indexes in a table which name is a number(1,2,3,4...)
But when i use the drop command to remove the index i get a 1064 error
DROP INDEX 1 ON table_name;
So my guess is that i cant drop an index when its name is a number? or there is something else i dont know here?
How can it work locally and not on the server?
Error output:
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 '1 on table_name' at line 1

Surround 1 with backticks, i.e.
DROP INDEX `1` ON table_name;

Related

Add calculated column to mySQL table

I'm trying to add column 'new_id' to table 'items_backup' with the following MySQL expression:
ALTER TABLE `items_backup`
ADD COLUMN `new_id` DOUBLE
GENERATED ALWAYS AS (`id`*100) STORED;
It is the multiplication of column 'id' by 100.
This is returning the error:
MySQL said: Documentation
#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 'GENERATED ALWAYS AS (`id`*100) STORED' at line 3
MySQL Version: 5.6.51
Can anyone help?

mysql VARBINARY datatype is not working while alter table column

mysql> ALTER TABLE googly MODIFY Data VARBINARY;
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 '' at line 1
mysql>
I am trying to alter my mysql database column using above query.
But it is giving me above error.
The reason i am using VARBINARY instead of BINARY is my data is too long.
BINARY giving me below error.
mysql.connector.errors.DataError: 1406 (22001): Data too long for column 'Data' at row 1
Is there any way to fix it ?
Please take a look.

deleting column containing white spaces in mysql

I was wondering how do I drop a column, containing spaces, in mysql.
Tried the following, and got the following exceptions:
alter table test17 drop column [added column2];
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 '[added column2]' at line 1
alter table test17 drop column 'added column2';
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 ''added column2'' at line 1
alter table test17 drop column (added column2);
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 '(added column2)' at line 1
Thanks:)
You should try using back ticks ("`") to quote your column name.
ALTER TABLE test17 DROP COLUMN `added column2`;
OR
Without COLUMN word
ALTER TABLE test17 DROP `added column2`;
Try:
alter table test17 drop column `added column2`;
Note that the quote characters are tilted left.
By the way, if you include spaces as part of identifier names (e.g. functions, procedures, tables, columns, etc.), that is a very, VERY bad practice.
First, column name with space is BAD PRACTICE. Then, if you really want to drop a column, use backtick instead:
ALTER TABLE test17 DROP COLUMN `added_column2`;

How to solve #1064 error in MySQL?

I got MySQL syntax Error 1064 while I am add new column.
ALTER TABLE `customerdetails` ADD `mobile` DOUBLE(12) NOT NULL ;
where customerdetails is the name of the table.
The Error message is " #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 ') NOT NULL' at line 1
Can somebody help me to solve this problem?
When you are defining column type as DOUBLE you have to define how many decimal places it will use
ALTER TABLE customerdetails ADD mobile DOUBLE(12,2) NOT NULL ;
Also first number (Characteristic) needs to be bigger than second number (Mantissa)

I am not able to create a table in MySQL from Ubuntu os

mysql> create table prasad1(empid number(1),name varchar(4));
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 'number(1),name varchar(4))' at line 1
This is the correct query create table prasad1(empid int(1),name varchar(4));
Explanation: There is not number field type in MySQL. You can use either int or integer.