NULL value for int in Update statement

Maanu picture Maanu · May 19, 2011 · Viewed 123.9k times · Source

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

How can I write the update statement in this case?

Answer

OMG Ponies picture OMG Ponies · May 19, 2011

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.