Can I change a column from NOT NULL to NULL without dropping it?
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;
B开发者_如何学Pythonut 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.
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
精彩评论