26

Is it possible to set NULL value for int column in update statement?

How can I write the update statement in this case?

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
Maanu
  • 5,093
  • 11
  • 59
  • 82

4 Answers4

34

Assuming the column is set to support NULL as a value:

UPDATE YOUR_TABLE
   SET column = NULL

Be aware of the database NULL handling - by default in SQL Server, NULL is an INT. So if the column is a different data type you need to CAST/CONVERT NULL to the proper data type:

UPDATE YOUR_TABLE
   SET column = CAST(NULL AS DATETIME)

...assuming column is a DATETIME data type in the example above.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
  • 3
    _by default in SQL Server, NULL is an INT_ That is not true and I doubt it ever was even way back in 2011. – juharr Sep 04 '15 at 15:28
7

By using NULL without any quotes.

UPDATE `tablename` SET `fieldName` = NULL;
Gaurav
  • 28,447
  • 8
  • 50
  • 80
3

Provided that your int column is nullable, you may write:

UPDATE dbo.TableName
SET TableName.IntColumn = NULL
WHERE <condition>
Alireza Maddah
  • 5,718
  • 2
  • 21
  • 25
2

If this is nullable int field then yes.

update TableName
set FiledName = null
where Id = SomeId
Alex Aza
  • 76,499
  • 26
  • 155
  • 134