Thursday, February 10, 2011

How do I set a column value to NULL in SQL Server Management Studio?

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

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

  • 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]
    
    From TheTXI
  • Ctrl+0 or empty the value and hit enter.

    From Eppz
  • 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 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.

    TheTXI : His question text asks about clearing the value from a cell, not an entire column. You would potentially have to do a where clause to find the particular record you want to edit.
    Michael Haren : @TheTXI good catch. As written, that SQL is mighty dangerous.
    Geoffrey Chetwood : Wow, this could be awful. Please change your answer!
    Geoffrey Chetwood : Fixed. Please read the question next time.
    Jeff Martin : I purposely left the condition off actually... if you look at the Big Bold Question of his title, he asks how you set a column to null.

0 comments:

Post a Comment