You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Database Articles/Behavior Of Nulls/readme.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,7 +77,7 @@ The following truth tables display how the three-valued logic is applied.
77
77

78
78
79
79
80
-
A good example of the complexity is shown below in the following examples. [De Morgan's Law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) is also included below, as I show both versions of negation.
80
+
A good example of the complexity is shown below. [De Morgan's Law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) is also included below, as I show both versions of negation.
81
81
82
82
```sql
83
83
--TRUE OR UNKNOWN = TRUE
@@ -96,7 +96,7 @@ SELECT 3 WHERE NOT(1=2) AND NOT(NULL=1);
96
96
97
97
>:exclamation: The standard setting for `ANSI_NULLS` is `ON`. In a future version of Microsoft SQL Server, `ANSI_NULLS` will always be `ON`, and any applications that explicitly set the option to `OFF` will produce an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
98
98
99
-
In Microsoft SQL Server, the `SET ANSI_NULLS` setting specifies the ISOcompliant behavior of the equality (=) and inequality (<>) comparison operators. The following table shows how the `ANSI_NULLS` session setting affects the results of Boolean expressions using NULL markers.
99
+
In Microsoft SQL Server, the `SET ANSI_NULLS` setting specifies the ISO-compliant behavior of the equality (=) and inequality (<>) comparison operators. The following table shows how the `ANSI_NULLS` session setting affects the results of Boolean expressions using NULL markers.
100
100
101
101
| Boolean Expression | SET ANSI_NULLS ON | SET ANSI_NULLS OFF |
NULL markers are neither equal to nor not equal to each other. They are treated as **UNKNOWN**. This is best demonstrated by the below `INNER JOIN` statement, where NULL markers are absent in the result set. Note here we are looking for both equality and inequality in the `Fruit` column.
222
+
NULL markers are neither equal to nor not equal to each other. They are treated as **UNKNOWN**. This is best demonstrated by the below `INNER JOIN` statement, where NULL markers are absent in the result set. Note that we are looking for both equality and inequality in the `Fruit` column.
The `FULL OUTER JOIN` will give an illusion that it matches the NULL markers, but looking closely at the number of NULL markers returned vs. the number of NULL markers in our sample data, we can determine this is indeed not true. Also, the below query demonstrates the `ORDER BY`sorts NULL markers in ascending order.
251
+
The `FULL OUTER JOIN` will give an illusion that it matches the NULL markers, but looking closely at the number of NULL markers returned vs. the number of NULL markers in our sample data, we can determine this is indeed not true. Also, the query below demonstrates the `ORDER BY`sorting NULL markers in ascending order.
252
252
253
253
```sql
254
254
SELECTa.ID,
@@ -310,7 +310,7 @@ WHERE a.Fruit IS DISTINCT FROM b.Fruit;
310
310
## Semi and Anti Joins
311
311
🔵 [Table Of Contents](#table-of-contents)
312
312
313
-
Semi-joins and anti-joins are two closely related join methods. The semi-join and anti-join are types of joins between two tables where rows from the outer query are returned based on the presence or absence of a matching row in the joined table.
313
+
Semi-joins and anti-joins are two closely related join methods. Semi-joins and anti-joins are types of joins between two tables where rows from the outer query are returned based on the presence or absence of a matching row in the joined table.
314
314
315
315
Anti-joins use the `NOT IN` or `NOT EXISTS` operators. Semi-joins use the `IN` or `EXISTS` operators.
316
316
@@ -330,7 +330,7 @@ Also, each of these joins can be used as a correlated subquery. Using `EXISTS`
This statement returns an empty dataset as the anti-join contains a NULL marker. Note that we are passing a set of parameters and not an SQL statement to the `NOT IN` clause.
333
+
This statement returns an empty dataset as the anti-join contains a NULL marker. Note that we are passing a set of parameters, not an SQL statement, to the `NOT IN` clause.
The following two SQL statements return the same results when using SUM, COUNT, AVG, MIN, MAX, etc.
692
+
The following two SQL statements return the same results when using `SUM`, `COUNT`, `AVG`, `MIN`, `MAX`, etc. For this example, we will use the `SUM` function.
693
+
694
+
When you do not specify an `ORDER BY` clause with a `SUM` windowing function, a total by the partitioning column is created. Using `SELECT NULL` in the `ORDER BY` produces the same results.
693
695
694
696
```sql
695
697
SELECT*,
@@ -810,7 +812,7 @@ Multiple NULL markers can be inserted into the child column that has a foreign k
810
812
811
813
In Microsoft SQL Server, a `FOREIGN KEY` constraint must be linked to a column with either a `PRIMARY KEY` constraint or a `UNIQUE` constraint defined on the column. A `PRIMARY KEY` constraint does not allow NULL markers, but a `UNIQUE` constraint allows one NULL marker.
812
814
813
-
In the following example, we show that inserting multiple NULL markers into the Child is possible.ParentID column. This reflects the unfortunate reality that a child may be orphaned and, therefore, not have an associated parent.
815
+
The following example shows that inserting multiple NULL markers into the Child is possible.ParentID column. This reflects the unfortunate reality that a child may be orphaned and, therefore, not have an associated parent.
814
816
815
817
Referential integrity cannot be created on temporary tables; for this example, we create two tables, `Parent` and `Child`.
816
818
@@ -888,7 +890,7 @@ When creating a table with a non-NULLable computed column, you must create the c
888
890
889
891
From this error message, we can see there are several rules we need to follow on computed columns if we want to add `UNIQUE`, `PRIMARY KEY`, `FOREIGN KEY`, `CHECK`, and `NOT NULL` constraints.
890
892
891
-
Here, we add a `NOT NULL` constraint to a `PERSISTED` computed column and add a `PRIMARY KEY`to the column.
893
+
Here, we add a `NOT NULL` constraint to a `PERSISTED` computed column and then run an 'ALTER TABLE' to create a `PRIMARY KEY`on the column.
0 commit comments