-2

I wanted to add Default to an existing column through alter command ,

alter table Student_Details modify column Student_Class enum('First','Second','Third') Default '{1}' ;

Is there any way to do it.

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
VijayIndia
  • 91
  • 1
  • 7
  • 1
    Well, do you see `{1}` in the declaration of `enum('First','Second','Third')`? No? Then this is your error. – fancyPants Oct 22 '15 at 05:28
  • @fancyPants i get error while using default keyword for an Alter command, "alter table Student_Details modify column Student_Class int Not Null default '{1}' " – VijayIndia Oct 22 '15 at 18:23

1 Answers1

0

The point of the enum datatype is to allow only certain values in a column. In your case that's 'First', 'Second' and 'Third'. Therefore you can not assign '{1}' as default value. You may have heard, that you can also use the index of each value in an enum, but then use 1 and not '1' and certainly not {1}. The ' make it a string and not a number and the {} is just not valid syntax. Actually I haven't tried to assign a default value with the index, I don't know if it's valid at all. Actually I avoid enum like poison, here are some reasons for it.

Anyway, make it

alter table Student_Details modify column Student_Class enum('First','Second','Third') Default 'First';

and it should work.

fancyPants
  • 50,732
  • 33
  • 89
  • 96