Lecture 3 - 3-valued SQL and NULL Flashcards

1
Q

What is the three-valued logic of SQL?

A

TRUE (1), FALSE (0) and UNKNOWN(0.5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the principles of NULL values?

A
  • That each null value is different from another
  • any value compared to NULL is null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do we need to adopt to compare to NULL?

A

IS / IS NOT NULL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

min / or with UNKNOWN?

A

Will evaluate to UNKNOWN unless there is a false and unknown combination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

max / and with UNKNOWN?

A

TRUE WITH UNKNOWN IS TRUE OTHERWISE UNKNOWN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

difference / not with NULL?

A

TRUE = FALSE
FALSE = TRUE
UNKNOWN = UNKNOWN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why won’t this work:

COMPARISON INVOLVING NULL
SELECT Fname, Lname
FROM EMPLOYEE
WHERE Super_ssn = NULL

A

As Super_ssn = NULL will always evaluate to unknown, which will false when we take min

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why won’t the following work?

SELECT *
FROM EMPLOYEE
WHERE DNO NOT IN (1, 2, NULL)

A

This won’t work as we are not checking for NULL with the IS statement, because of this the boolean will result in UKNOWN, which when the min / and is taken we get UNKNOWN (i.e. when DNO = 3).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly