How can I alter a column whose restricted to NOT NULL to accept NULL values?
alter table yourTableName modify column yourColumnName datatype; Apply the above syntax to modify the column to allow NULL. The query is as follows. After executing the above query, you can insert NULL value to that column because the column is modified successfully above.
All you need to do is to replace [Table] with the name of your table, [Col] with the name of your column and TYPE with the datatype of the column. Execute the command and you are allowed to use NULL values for the specified column. That is all it takes to switch between NULL and NOT NULL .
We can remove a NOT NULL constraint from a column of an existing table by using the ALTER TABLE statement.
just modify it and put in the old type and leave off the not null
alter table table_name modify column foo int;
Assuming the table is table_name, column is column_name and its defined as varchar(200):
alter table table_name modify column column_name varchar(200) default null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With