Set false in a specific column for all rows

I have a table with the following columns:

ID    Name 
1     test1
2     test2

Now I have added a new column IsConfirmed. And this column contains nullin all rows.

ID    Name   IsConfirmed
1     test1     null
2     test2     null

How can I set a column falsein IsConfirmedfor all rows of a table using T-SQL?

thank

+5
source share
2 answers
UPDATE YourTableName
SET IsConfirmed=0
WHERE isConfirmed is Null

It doesn’t mean to be rude, but have you made any efforts to research this question before asking?

+17
source

The @JohnFx proposal is the perfect solution to the problem. However, you may be interested in learning how to prevent this from happening and, at the same time, solve other potential problems.

, , NULL 0, , , NULL . , NOT NULL:

ALTER TABLE tablename
ADD IsConfirmed bit NOT NULL

, NOT NULL , , , SQL Server NULL, , , . , NOT NULL:

ALTER TABLE tablename
ADD IsConfirmed bit NOT NULL
CONSTRAINT DF_tablename_IsConfirmed DEFAULT (0)

CONSTRAINT DF_tablename_IsConfirmed , DEAFULT (0), , , / . ( ) . (DF DEFAULT, , ) , . , .

+1

All Articles