MS SQL Update WHERE value is NULL

This example replaces null with an empty string in SomeTable.SomeColum

UPDATE SomeTable SET SomeColumn = '' WHERE SomeColumn IS NULL

The important thing to note here is that the check to find the value that is NULL is based on “IS NULL” (it is not possible to use the equals sign to check for NULL)

MS SQL SELECT WHERE value is NULL

Here is how to do a select where a column have NULL as the stored value.

SELECT * FROM SomeTable WHERE SomeColumn IS NULL

Equals sign does not work for null, trying to use the equals operator generates the result Unknown (it is not true nor false)

IF i = NULL THEN
      SELECT 'Result is True'
ELSEIF NOT(i = NULL) THEN
      SELECT 'Result is False'
ELSE
      SELECT 'Result is Unknown';
 
--This will end with Result is Unknown

This is based on the fact that null was introduced to represent “missing information and inapplicable information” in the database model and based on that statement using equals null was not implemented.

SQLServer Adding a column to a table

Adding a column to existing table is not that hard. One thing to keep in mind, if the column is not nullable then a default value is mandatory.

ALTER TABLE {TABLENAME} 
ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} 
CONSTRAINT {CONSTRAINT_NAME} 
DEFAULT {DEFAULT_VALUE}