Mysql error #1064 when renaming columns - mysql

I am gettting a mysql error when trying to change the column names on these tables:
alter field_data_commerce_customer_address CHANGE field_mcaf_middle_name commerce_customer_address_middle_name varchar (255);
alter field_revision_commerce_customer_address CHANGE field_mcaf_middle_name commerce_customer_address_middle_name varchar (255);
This is my 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 'field_data_commerce_customer_address CHANGE field_mcaf_middle_name commerce_cust' at line 1
I checked the table and column names and they are correct. What am I missing

You missed 'TABLE' word:
alter TABLE field_data_commerce_customer_address CHANGE field_mcaf_middle_name commerce_customer_address_middle_name varchar (255);
alter TABLE field_revision_commerce_customer_address CHANGE field_mcaf_middle_name commerce_customer_address_middle_name varchar (255);

Related

Not able to alter a column to accept null values for int datatype

Query :
ALTER TABLE db.tbl_name ALTER COLUMN column_name INT NULL
Error : 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 'INT NULL' at line 1
Please try the following:
ALTER TABLE db.tbl_name Modify COLUMN column_name INT NULL
This is a good read :)

Mysql syntax error in ALTER TABLE

Sql keeps throwing me a syntax error and I can't seem to figure out whats wrong.
ALTER TABLE `productList` ALTER COLUMN `ASIN` VARCHAR(32);
The error is the normal sql syntax 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 'VARCHAR(32)' at line 1
Try this:
ALTER TABLE `productList` MODIFY COLUMN `ASIN` VARCHAR(32);
The syntax to change the column name is
ALTER TABLE tablename MODIFY COLUMN new-column-definition
You need to use MODIFY COLUMN instead of ALTER COLUMN if you want to change the column definition.
https://dev.mysql.com/doc/refman/5.1/en/alter-table.html
It's modify, not alter column.
ALTER TABLE table_name
MODIFY column_name column_definition
[ FIRST | AFTER column_name ];

mysql error 1064 with statement ALTER COLUMN

Following statement gives me an error:
ALTER TABLE employee ALTER COLUMN Startdate datetime
Error:
Mysql error 1064
Mysql does not use ALTER COLUMN.
ALTER TABLE table_name
MODIFY COLUMN column_name datatype
Please Try the following
ALTER TABLE `DbName`.`table_name`
CHANGE COLUMN `column_name` `new_col_name` VARCHAR(250) NOT NULL DEFAULT '' ;
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
Usage: mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --databa at line 1

Insert Column Name into Table if Column Name does not already exist

IF COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` ADD `name` INT(32) UNSIGNED NOT NULL;
END
I am trying to write some sql that will insert a column name into the table "Characters" if it is not already existant, however I am getting errors which I do not understand (quite new to SQL) and I could use some help understanding why it is not working. I have gotten the IF part from another Question, and the ALTER part from the DBMS I'm using, PhpMyAdmin 2.11.4.
It is using MySQL 5.6 apparently and this is 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 'IF COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` AD' at line 1

Error when enterting this command ALTER TABLE `report` AUTO_INCREMENT = 1

I get an error when using this command to alter my SQL table
Error message:
#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 'ALTER TABLE `report` AUTO_INCREMENT = 1, 30' at line 2`
Any idea of that?
So why would you say AUTO_INCREMENT=1,30 ?
It has to be one number, and not a comma separated list of numbers.
ALTER TABLE report AUTO_INCREMENT=1
or
ALTER TABLE report AUTO_INCREMENT=30
Reference: MySQL