List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 4 2002 1:40am
Subject:Re: change column to not null in MySQL
View as plain text  
At 16:59 -0500 3/3/02, shiam@stripped wrote:
>Is there any way in mysql to change a column that contains data
>from null = yes to be not null.

Use the ALTER TABLE statement.

>
>I want to enforce users to enter some value in column_x that was
>not a required field until now, by setting the column to not accept
>any record where column_x is null, is there any way to do this
>without distorting current data (I guess I will have to give some
>bogus value for all the data field's that are now null before I can
>change this).?

That's correct. Otherwise when you alter the column's definition,
MySQL will convert the NULL values to some non-NULL value (probably
the default value, although I haven't tested that).  By changing the
value before you alter the column, you can choose the value yourself.

>
>If the column type cannot be changed what's the recommended
>way of doing something like this.
>
>Thanks
>
>Shia
>Shia Meisels
>B&H Photo Video
>212-239-7500 Ext. 2158
>http://www.bhphotovideo.com

Thread
change column to not null in MySQLshiam3 Mar
  • Re: change column to not null in MySQLPaul DuBois4 Mar
  • RE: change column to not null in MySQLAl Caponi4 Mar
    • RE: change column to not null in MySQLPaul DuBois4 Mar