MySQL SET NULL Values in UPDATE StatementBy using the assignment operator (“=”), you can set any value of a column to NULL by using the Update Statement.
If you've opened a table and you want to clear an existing value to NULL, click on the value, and press Ctrl + 0 .
You can right-click on a cell and choose "Clear Field Content" in the popup menu. It will set the cell value to NULL.
In MySQL Workbench, right click on the cell and select 'Set Field to NULL'. In MySQL Workbench this setting is now called Set Field(s) to NULL , and is the first option in the list.
Don't put NULL
inside quotes in your update statement. This should work:
UPDATE table SET field = NULL WHERE something = something
You're probably quoting 'NULL'. NULL is a reserved word in MySQL, and can be inserted/updated without quotes:
INSERT INTO user (name, something_optional) VALUES ("Joe", NULL);
UPDATE user SET something_optional = NULL;
UPDATE MyTable
SET MyField = NULL
WHERE MyField = ''
You should insert null
, not the string of 'NULL'
.
Use NULL
(without the quotes around it).
UPDATE users SET password = NULL where ID = 4
if (($_POST['nullfield'] == 'NULL') || ($_POST['nullfield'] == '')) {
$val = 'NULL';
} else {
$val = "'" . mysql_real_escape_string($_POST['nullfield']) . "'";
}
$sql = "INSERT INTO .... VALUES ($val)";
if you put 'NULL'
into your query, then you're just inserting a 4-character string. Without the quotes, NULL
is the actual null value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With