Can I change a column from NOT NULL to NULL without dropping it?
Sql ServerSql 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