Need to alter a table to allow nulls on a column -- but cant drop the column...can I do this? Was trying something like:
ALTER TABLE myTable MODIFY myColumn NULL;
But to no avail....
ALTER TABLE myTable ALTER COLUMN myColumn {DataType} NULL
where {DataType}
is the current data type of that column (For example int
or varchar(10)
)
Sure you can.
ALTER TABLE myTable ALTER COLUMN myColumn int NULL
Just substitute int for whatever datatype your column is.
alter column
and it didn't work with the latest mysql server. I tried with modify column
and it worked. Strange...
Aug 19, 2017 at 15:29
The syntax is very based on database service
SQL Server / MS Access:
ALTER TABLE table_name
ALTER COLUMN column_name datatype NULL;
My SQL / Oracle (prior version 10G):
ALTER TABLE table_name
MODIFY COLUMN column_name datatype NULL;
Oracle 10G and later:
ALTER TABLE table_name
MODIFY column_name datatype NULL;
if you want to set a default value then:
ALTER TABLE table_name
ALTER COLUMN column_name datatype DEFAULT default_value;
For MYSQL
ALTER TABLE myTable MODIFY myColumn {DataType} NULL