Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value to NULL in MySQL

Tags:

sql

mysql

People also ask

How do you change a value to NULL in MySQL?

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.

How do you set a value to NULL in SQL?

If you've opened a table and you want to clear an existing value to NULL, click on the value, and press Ctrl + 0 .

How do you set a NULL value in SQL Workbench?

You can right-click on a cell and choose "Clear Field Content" in the popup menu. It will set the cell value to NULL.

How do you set a field to NULL in MySQL workbench?

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.