Update 语句中 int 的 NULL 值
问题描述:
是否可以在更新语句中为 int 列设置 NULL 值?
Is it possible to set NULL value for int column in update statement?
在这种情况下如何编写更新语句?
How can I write the update statement in this case?
答
假设列设置为支持 NULL 作为值:
Assuming the column is set to support NULL as a value:
UPDATE YOUR_TABLE
SET column = NULL
注意数据库 NULL 处理 - 默认情况下,在 SQL Server 中,NULL 是一个 INT.因此,如果该列是不同的数据类型,您需要将 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)
...假设 column
是上述示例中的 DATETIME 数据类型.
...assuming column
is a DATETIME data type in the example above.