mysql怎么update一个值为null?

mysql怎么update一个值为null?,第1张

update tblname set 字段=null where condition; 直接用常量Null。

这个是有条件限制的。可以先select from table_name查看一下表中想设置的那个列的属性是否设置了NOT NULL,如果设置了NOT NULL,那么是不能简单的修改为NULL的。必须先修改这个列的属性,alter table table_name set (列名) varchar(100) default null现在就是默认为空,如果查询出来是允许为空,直接update 表名 set 列名=null where 条件即可。

update 表名 set 字段 = null where id=1 --把字段数据变成null
update 表名 set 字段 = 值 where 字段 is null --改写字段为null数据
update 表名 set 字段 = null where 字段 is not null --把字段不为null变成null

ContentValues initialValues = new ContentValues();

initialValuesput(KEY_NAME, name);

initialValuesput(KEY_EMAIL, email);

return dbinsert(DATABASE_TABLE, null, initialValues);

如果你只是某几列为空,你可以使用上面的语句,为空的列不要设置。

如果你想插入一个空行,所有的数据都不填入值,要使用下面的方式

return dbinsert(DATABASE_TABLE, "某列的名称", null);

也就是说,你至少要指定一个空列的列名。

请使用参数
例子:
string str = "update table set colName = @colValue where key = @value"
SqlCommand scom = new SqlCommand();
SqlParameter sp = new SqlParameter("@colValue",SqlDbType你的列类型);
spValue = DBNullValue;
scomExcuteNonquery();


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13141696.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-11
下一篇 2023-06-11

发表评论

登录后才能评论

评论列表(0条)

保存