开发者_Python百科Revisiting MySQL, and trying to change the structure of the table. I want to change two rows from a varchar(30) to higher.
I have googled it, and tried what appears to be the correct statement but I'm getting a syntax error:
ALTER TABLE 'compdetails' CHANGE 'compName' varchar(60) not null;
This statement however gives me a syntax error. I have also tried without the '' around the table/column names without any luck.
"Error 2064 (42000): You have an error in your SQL Syntax...."
Can anyone jog my memory?
Just so:
ALTER TABLE 'compdetails' CHANGE compName compName varchar(60) not null;
Firstly, if you want to quote table names, then you need to use back ticks not single quotes. A single quote is only used for string literals.
Secondly, CHANGE is used when you want to rename the column, whereas MODIFY allows you to change the column definition without renaming it. So you should be using:
ALTER TABLE compdetails MODIFY compName varchar(60) NOT NULL;
The online MySQL documentation is very good and I would encourage you to check it whenever you come across problems with syntax.
ALTER TABLE `compdetails` MODIFY COLUMN `compName` varchar(60) not null;
精彩评论