-1

I am trying to add a simple column in my table in MySQL but it is giving syntax error:

Error Code: 1064

You have an error in your SQL syntax;

Code:

ALTER TABLE `user`
ADD classname VARCHAR 150 NULL AFTER id;
Community
  • 1
  • 1
  • As a pointer for your next question: mysql tells you where the syntax error occured in the statement, so next time share that part with us as well. – Shadow Mar 01 '18 at 06:49
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 01 '18 at 09:54

4 Answers4

3

try:

ALTER TABLE `user`
ADD classname VARCHAR(150) NULL AFTER id;
flik
  • 3,433
  • 2
  • 20
  • 30
3

The length of the varchar type must be enclosed by brackets:

ALTER TABLE `user`
ADD classname VARCHAR(150) NULL AFTER id;
Shadow
  • 33,525
  • 10
  • 51
  • 64
3

the length of a field n sql must be enclosed with (),but you have missed the paranthesis(),so you were getting the error,just try with ()

ALTER TABLE `user`
ADD classname VARCHAR(150) NULL AFTER id;
2

extra parenthesis is required for datatype

ALTER TABLE `user`
ADD classname VARCHAR(150) NULL AFTER id;
user9405863
  • 1,506
  • 1
  • 11
  • 16