I am trying to remove not null constraint in sql server 2008 without losing data.
Asked
Active
Viewed 1.8e+01k times
4 Answers
239
ALTER TABLE YourTable ALTER COLUMN YourColumn columnType NULL
Omu
- 67,351
- 88
- 268
- 400
Michael Pakhantsov
- 24,077
- 5
- 58
- 59
-
5I found I had to include the type in YourColumn eg. ALTER TABLE YourTable ALTER COLUMN YourColumn int NULL – Adam Butler Jun 28 '11 at 01: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) – nr5 Sep 19 '12 at 18:11
-
60In postgres: `ALTER TABLE YourTable ALTER COLUMN YourColumn DROP NOT NULL` – Shane Mar 20 '13 at 16:41
4
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. – Orchidoris Feb 18 '19 at 14:00
0
Remove column constraint: not null to null
ALTER TABLE test ALTER COLUMN column_01 DROP NOT NULL;
PasQualE
- 17
- 4
-
1That 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 '19 at 14:06