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.

Answer from OMG Ponies on Stack Overflow
🌐
W3Schools
w3schools.com › sql › sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
String Functions: Asc Chr Concat ... SQL Study Plan SQL Bootcamp SQL Certificate SQL Training ... A field with a NULL value is a field with no value....
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 911838 › sql-query-needs-to-handle-both-null-and-integer-va
Sql query needs to handle both NULL and INTEGER value. - Microsoft Q&A
Welcome to Microsoft T-SQL Q&A Forum! First of all, your function is not used correctly . When you want to determine whether a field exists , when the database retrieves null , it will of course return 0 because of your operation .
🌐
SQL Team
sqlteam.com › forums › topic.asp
Default NULL for INT data types - SQL Server Forums
Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
🌐
Microsoft
social.msdn.microsoft.com › Forums › sqlserver › en-US › 476a2985-983e-4681-90e9-88f50b8766b5 › null-recognized-as-int
NULL recognized as int? | Microsoft Learn
So, for example, if you have a column where one of the UNIONed queries has a varchar and another of the queries has a NULL, the resulting column will be an int, because int has a higher precedence than varchar. So SQL will attempt to convert the varchar values to an int and give you an error if a row has a value that cannot be converted.
🌐
TutorialsPoint
tutorialspoint.com › insert-null-value-into-int-column-in-mysql
Insert NULL value into INT column in MySQL?
You can insert NULL value into an int column with a condition i.e. the column must not have NOT NULL constraints. The syntax is as follows. INSERT INTO yourTableName(yourColumnName) values(NULL); To under
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › sql-change-null-values-for-integer-column
SQL Change null values for integer column – SQLServerCentral Forums
November 9, 2022 - The text file is having null-empty values and MYSQL load is errors out with Incorrect integer value.
🌐
W3Schools
w3schools.com › sql › sql_notnull.asp
SQL NOT NULL Constraint
The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values when the "Persons" table is created: CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int );
🌐
HeidiSQL
heidisql.com › forum.php
Can't set integer field to null
SQL Error: Incorrect integer value: '' for column 'zip' at row 1 However, the following sql code works from a command line prompt: UPDATE table SET zip=null WHERE id=#; Where table is the name of the table and # is the id for the record that I am updating. Does anyone know how to enter null ...
Find elsewhere
Top answer
1 of 8
26

At Uni I was taught that the opposite is true. It's much more dangerous to make something not null without reason. With a nullable field the worst thing that can happen is you trip over the application accessing the data. Oh dear, go back and fix the app...

With a not-null field you make it impossible to add record because some arbitrary field isn't available. Now you need to change the data model and potentially fix the result in a LOT of different places...

It's good to think of null as "unknown". If there's any plausible reason why you might want to enter a record without knowing something then it should be nullable.

One of my university lecturers described it like this:

Apocryphally I've heard of a sales system in the USA which required customer's social security number to make a sale. All the till operators did when a foreigner came to the till was enter 000-00-0000. But then others would enter 123-45-6789. This makes it impossible to identify junk. It's much better to allow a field to be blank than to force it to contain junk.

Or another story. I have genuinely been refused car insurance because I don't have two phone numbers. They absolutely would not give me insurance unless I gave them two. The sales guy suggested I just give a false one. In the end I refused to lie to an insurer and just went with another company.

In practice reserve not null for fields which are required to make sense of the record. For example:

A table of places with fields (ID, Place Name, Country, Longitude, Latitude) ... "longitude" "latitude" should be nullable so that you can store the existence of a place before you know where it is.

But if you have a table who's sole purpose is to store geographical coodinates with fields (Item_id, longitude, latitude) the entire record is meaningless if longitude and latitude are null. Therefore in this instance they should be not-null

In my professional experience since uni, there are far more fields which can optional than need to be mandatory.

2 of 8
8

It strikes me as extremely counter-intuitive...

Intuitive is in the eye of the beholder and your opinion on that is shaped by the things to which you've been exposed. I hail from a time when that kind of safety wasn't standard and the tools didn't point out when you goofed up. I've been using the chain saw without a blade guard long enough that my first instinct is to avoid intuition entirely, go back to the DDL and find out exactly what assumptions the schema will let me make about its data.

...and potentially dangerous for allowing NULL's to be the default behavior.

I think you're overstating the relative dangers. NOT NULL has its own set of pitfalls that can lead to equally-insidious bugs. (Enumerating them would be fodder for a different question.)

The designer of a table always has the option of constraining a column NULL or NOT NULL and will do one or the other to get around the default, whatever it is. Not constraining a column correctly is a developer's failure to follow the business rules. Not doing the right thing elsewhere based on the column's definition is a developer's failure to understand the data he's being handed. There's no technical fix for either.

Still, I have to ask, is there any good reason for the language to be designed this way, with types being nullable by default?

No, there isn't. Because both have hazards, there's also no good reason for the language to be designed the other way. It boils down to picking your poison.

🌐
Baeldung
baeldung.com › home › persistence › inserting null into an integer column using jdbc
Inserting Null Into an Integer Column Using JDBC | Baeldung
January 8, 2024 - To set a null value into the Integer column, there are two defined ways in the PreparedStatement interface. With the setNull method, we’re always sure that our field value is null before executing the SQL query.
🌐
Wikibooks
en.wikibooks.org › wiki › MySQL › Language › Using_NULL
MySQL/Language/Using NULL - Wikibooks, open books for an open world
October 15, 2010 - Null is a special logical value in SQL. Most programming languages have 2 values of logic: True and False. SQL also has NULL which means "Unknown". A NULL value can be set. NULL is a non-value, so it can be assigned to TEXT columns, INTEGER columns or any other datatype.
🌐
DB Vis
dbvis.com › thetable › the-definitive-guide-to-the-null-sql-server-value
The Definitive Guide to the NULL SQL Server Value
September 12, 2024 - To mark a column as nullable in SQL Server, you can add the NULL keyword in the column definition line of your CREATE TABLE, as in the example below: ... 1 CREATE TABLE Employee ( 2 Id INT NOT NULL IDENTITY(1,1) PRIMARY KEY, 3 FirstName VARCHAR(50) ...
🌐
Scriptcase
forum.scriptcase.net › applications › forms
how to insert null instead of 0 for integer data type? - Forms - Scriptcase Low-code
September 3, 2014 - Hi all, Im using scriptcase v8 and oracle as database. When creating a form, i will have items withe integer data type via front end (number in oracle back end). but there are occasions where i don’t need this field to …
🌐
Ask LibreOffice
ask.libreoffice.org › english
Input a Null or blank value in an integer-type table field - English - Ask LibreOffice
January 6, 2020 - Hello, I have an Insert Into SQL command in a macro which inputs new record in a table, using values (some fields are string-type, some are integer-type) coming a dialog. Basically, I enter new records, and some of them…
🌐
IBM
ibm.com › docs › en › informix-servers › 14.10.0
SQL NULL value
We cannot provide a description for this page right now
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › null-values-to-int-parameter-in-the-stored-procedure
Null values to Int parameter in the Stored Procedure – SQLServerCentral Forums
June 28, 2011 - As currently defined your procedure actually allows @b-2 to be null - what it doesn't do is it doesn't allow you to skip passing the parameter.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › empty-string-inserts-as-0-to-int-column-how-to-prevent-it
empty string INSERTs as 0 to INT column - how to prevent it? – SQLServerCentral Forums
March 19, 2014 - SQLNYC · Luis Cazares · SSC Guru ... CAST('' AS datetime), CAST('' AS bit) The question is what do you want instead of the zero? you can't have an empty string in an int column. You could have a zero or a NULL value, both values are different....