13-Jun-03 (Created: 13-Jun-03) | More in 'CS-SQLServer'

One quick way to document joins in SQL/Stored Procedures

Actual code

from      stop_detail_requirements sdi
     join orders o on o.order_id = sdi.order_id
     left outer join unitload_detail     ud on ud.stop_detail_req_id =
sdi.stop_detail_req_id
     left outer join unitload            ul on  ul.unitload_number =
ud.unitload_number
     left outer join part_packaging           pp on pp.packaging_id =
sdi.packaging_id
     left outer join container           c on c.container_id =
pp.prmpk_container_id

Aid to quick understanding

o -> sdr (n)
     -> pp -> c
     -> ud -> ul

How to read

  1. 1. An order leads to multiple stop detail requirements
  2. 2. An "sdr" can independently yield 1 "pp - part packaging" and 1 "ud - unitload detail"
  3. 3. A "pp" can lead to a single container "c"
  4. 4. A "unitload detail" can lead to a single "unitload"