Can I change a column from NOT NULL to NULL without dropping it?

Sql Server

Sql Server Problem Overview


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

Sql Server Solutions


Solution 1 - Sql Server

ALTER TABLE myTable ALTER COLUMN myColumn {DataType} NULL

where {DataType} is the current data type of that column (For example int or varchar(10))

Solution 2 - Sql Server

Sure you can.

ALTER TABLE myTable ALTER COLUMN myColumn int NULL

Just substitute int for whatever datatype your column is.

Solution 3 - Sql Server

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;

Solution 4 - Sql Server

For MYSQL

ALTER TABLE myTable MODIFY myColumn {DataType} NULL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTodd VanceView Question on Stackoverflow
Solution 1 - Sql ServerWilView Answer on Stackoverflow
Solution 2 - Sql ServerMark S. RasmussenView Answer on Stackoverflow
Solution 3 - Sql ServerVipulVyasView Answer on Stackoverflow
Solution 4 - Sql ServerPrakash BhandariView Answer on Stackoverflow