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.
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.
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.