Skip to content

Commit

Permalink
Fix #103 - Consistent use of Example subchapters
Browse files Browse the repository at this point in the history
  • Loading branch information
kibeha committed Jul 15, 2022
1 parent 458b217 commit 7b50d70
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
32 changes: 14 additions & 18 deletions docs/4-language-usage/3-dml-and-sql/1-general/g-3120.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ select last_name
where extract(month from hire_date) = extract(month from sysdate);
```

If the `jobs` table has no `employee_id` column and `employees` has one this query will not raise an error but return all rows of the `employees` table as a subquery is allowed to access columns of all its parent tables - this construct is known as correlated subquery.

``` sql
select last_name
,first_name
from employees
where employee_id in (
select employee_id
from jobs
where job_title like '%Manager%'
);
```

## Example (better)

``` sql
Expand All @@ -47,23 +60,6 @@ select emp.last_name
where extract(month from emp.hire_date) = extract(month from sysdate);
```

## Example Subquery (bad)

If the `jobs` table has no `employee_id` column and `employees` has one this query will not raise an error but return all rows of the `employees` table as a subquery is allowed to access columns of all its parent tables - this construct is known as correlated subquery.

``` sql
select last_name
,first_name
from employees
where employee_id in (
select employee_id
from jobs
where job_title like '%Manager%'
);
```

## Example Subquery (good)

If the `jobs` table has no `employee_id` column this query will return an error due to the directive (given by adding the table alias to the column) to read the `employee_id` column from the `jobs` table.

``` sql
Expand All @@ -75,4 +71,4 @@ select emp.last_name
from jobs j
where j.job_title like '%Manager%'
);
```
```
4 changes: 3 additions & 1 deletion docs/4-language-usage/3-dml-and-sql/1-general/g-3195.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ select e.employee_id

## Example (good)

Using a wildcard:

``` sql
select e.employee_id
,e.last_name
from employees e
where e.last_name like 'Smith%';
```

## Example (good)
Change to equality operator instead:

``` sql
select e.employee_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ end;
/
```

## Example (better)
## Example (best)

(Assuming suitable foreign key relationship exists to allow updating a join.)

Expand Down
2 changes: 1 addition & 1 deletion docs/4-language-usage/5-exception-handling/g-5040.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end;
/
```

## Example (exception to the rule)
An exception to the rule where `when others` can be good to log the error and then re-raise it:

``` sql
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end department_api;
/
```

## Function call
The exception should be handled where the function is called, like this:

``` sql
...
Expand Down

0 comments on commit 7b50d70

Please sign in to comment.