Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL: update a column to null

A learner here. This has to be esasy but I cannot figure it out.

I have a table like this:

ID -- NAME -- CHOICE
1 -- John -- book
2 -- Matt -- pen
3 -- Linda -- bag
.
.

What would be the script to turn all the data in column CHOICE to null?

Thanks a ton

like image 458
user712027 Avatar asked Feb 24 '12 09:02

user712027


People also ask

How do you UPDATE a column WHERE value is NULL?

UPDATE [table] SET [column]=0 WHERE [column] IS NULL; Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them.

How do you UPDATE an existing column in SQL?

First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.

How do I empty a column in SQL?

Right-click the column you want to delete and choose Delete Column from the shortcut menu. If the column participates in a relationship (FOREIGN KEY or PRIMARY KEY), a message prompts you to confirm the deletion of the selected columns and their relationships. Choose Yes.


1 Answers

You'd use an UPDATE statement, without a WHERE clause (so it updates every single row)

UPDATE YourTable
SET Choice = NULL
like image 64
AdaTheDev Avatar answered Nov 03 '22 00:11

AdaTheDev