305

How do I clear the value from a cell and make it NULL?

king_nak
  • 11,313
  • 33
  • 58
Zack Peterson
  • 56,055
  • 78
  • 209
  • 280

7 Answers7

436

I think Zack properly answered the question but just to cover all the bases:

Update myTable set MyColumn = NULL

This would set the entire column to null as the Question Title asks.

To set a specific row on a specific column to null use:

Update myTable set MyColumn = NULL where Field = Condition.

This would set a specific cell to null as the inner question asks.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jeff Martin
  • 10,812
  • 7
  • 48
  • 74
228

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

brutzen
  • 17
  • 7
Zack Peterson
  • 56,055
  • 78
  • 209
  • 280
52

If you are using the table interface you can type in NULL (all caps)

otherwise you can run an update statement where you could:

Update table set ColumnName = NULL where [Filter for record here]
TheTXI
  • 37,429
  • 10
  • 86
  • 110
13

Use This:

Update Table Set Column = CAST(NULL As Column Type) where Condition

Like This:

Update News Set Title = CAST(NULL As nvarchar(100)) Where ID = 50
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Milad
  • 147
  • 1
  • 2
  • 8
    Care to explain why your answer is better than the others? I mean you post this about almost half a year later. – fancyPants May 29 '12 at 14:20
7

Ctrl+0 or empty the value and hit enter.

Eppz
  • 3,178
  • 2
  • 19
  • 26
  • 4
    Emptying the value and clicking enter will not create a NULL value. If the column is a string datatype (varchar and the like), it will create an empty string. If the column is a numeric datatype (int and the like) it will pop up an Invalid Value error. And so on. NULL is the absence of a value, and is does not mean "blank." – undrline - Reinstate Monica Apr 08 '19 at 16:49
0

Just as a little extension to Jeff Martin's and Zack Peterson's solution.

If you still want to set several values from the columns to null you can simply set the query to

UPDATE myTable SET MyColumn1 = NULL, MyColumn2 = NULL, MyColumn3 = NULL, ...
41 72 6c
  • 1,600
  • 5
  • 19
  • 30
-1

CTRL+0 doesn't seem to work when connected to an Azure DB.

However, to create an empty string, you can always just hit 'anykey then delete' inside a cell.

Lee Smith
  • 6,339
  • 6
  • 27
  • 34
  • This not working in Azure DB is because the Ctrl+0 shortcut is specific to SSMS (and its predecessor, Enterprise Manager). Azure SQL Server features are all built in an entirely new interface on the web. – TylerH Sep 24 '20 at 18:28