NULL value for int in Update statement

2019-04-18 02:28发布

问题:

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

How can I write the update statement in this case?

回答1:

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.



回答2:

By using NULL without any quotes.

UPDATE `tablename` SET `fieldName` = NULL;


回答3:

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

UPDATE dbo.TableName
SET TableName.IntColumn = NULL
WHERE <condition>


回答4:

If this is nullable int field then yes.

update TableName
set FiledName = null
where Id = SomeId