A simple SQL quiz

Today at work a colleague came up with a really interesting question. Let’s consider this :

We have a table that has two columns Id, IsValid.

Id is our primary key, while IsValid is a not null bit column.

Can we flip the values of IsValid column in one query?

For example if we have:

Id IsValid
1 0
2 1
3 0

with a single update script to become

Id IsValid
1 1
2 0
3 1

Is it possible?

13 Comments

Add a Comment (gravatar-enabled)