I am trying to remove not null constraint in sql server 2008 without losing data.
4 Answers
ALTER TABLE YourTable ALTER COLUMN YourColumn columnType NULL
-
5I found I had to include the type in YourColumn eg. ALTER TABLE YourTable ALTER COLUMN YourColumn int NULL Jun 28, 2011 at 1:16
-
or you can do : alter table table_name modify column_name type(30) NULL. 30 being the size of your column type, example: varchar(30)– nr5Sep 19, 2012 at 18:11
-
60In postgres:
ALTER TABLE YourTable ALTER COLUMN YourColumn DROP NOT NULL
– ShaneMar 20, 2013 at 16:41
Remove constraint not null
to null
ALTER TABLE 'test' CHANGE COLUMN 'testColumn' 'testColumn' datatype NULL;
-
-
3@HopeKing the question was about Microsoft SQL Server and not MySql. Feb 18, 2019 at 14:00
Remove column constraint: not null
to null
ALTER TABLE test ALTER COLUMN column_01 DROP NOT NULL;
-
2That doesn't look like valid T-SQL. Although the question was marked with SQL, note that the question explicitly refers to SQL Server which only accepts T-SQL.– TT.Apr 18, 2019 at 14:06
ALTER TABLE tableName MODIFY columnName columnType NULL;