Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
ALTER TABLE sample62 CHANGE newcol c;

This code makes me mad. I just followed the book I had.

Program said

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.

My MySQL version is 5.7. Can you please help me?

share|improve this question

mysql error 1064

The error that gets thrown if the syntax is wrong. You did not clearly state what you are doing.

If you are changing a column

ALTER TABLE table_name MODIFY COLUMN column_name datatype

If you are trying to change column definition

ALTER TABLE table_name CHANGE old_column_name new_column_name data_type(size)

If you are adding a new column

ALTER TABLE table_name ADD column_name datatype
share|improve this answer
1  
What is "change column definition" as opposed to "changing a column"? – Andriy M Feb 10 at 12:25
    
"change column definition" - this includes renaming the column and more stuffs. – Vhortex Feb 11 at 3:24

I believe MySQL requires the ALTER TABLE ... CHANGE ... statement to restate the column definition (datatype, default value, column constraints &c.) even if it's only the column name being changed.

share|improve this answer

You can write your query like this:

ALTER TABLE database_name.sample62 CHANGE old_column_name new_column_name INT(11) DEFAULT 0 NULL;
share|improve this answer

Use this syntax:

Alter table tablename CHANGE [COLUMN] old_col_name new_col_name column_definition
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.