Question

Can someone explain, by example, how to read sqlite flowcharts and diagrams on the sqlite website?

For example, a diagram like:

sqlite diagram

How do I read this - and what does it mean?

Was it helpful?

Solution

The flowchart above gives you the valid ways to write a select statement. Just follow the arrow and you can see what you can do.

Reading this, you can see that you must start at SELECT. Then you can either go straight to the result-column or put in either DISTINT or ALL (but not both, because there is no way to follow the arrows and put them both in).

Once you get to the result-column, you can continue, or put a comma and another result-column. You can loop there as many times as you want.

From there you can go all the way to the end, or put in any of the FROM, WHERE or GROUP BY clauses (but they have to go in that order if they are there). The GROUP BY clause can have an optional HAVING clause.

In the end, it is just a flow chart. Follow the arrows. This diagram doesn't explain what this stuff does however, it only explains what makes a legal statement.

OTHER TIPS

The diagram that you're seeing is more like a State Machine Diagram for which you can find good information State Machines. A state machine diagram only starts from one state and ends in another state. For example, the starting point in shown diagram is the circle before "SELECT" and the end state is the last circle on bottom.

Transitioning from one state to another is based on the input you're gonna received. For example, here by seeing "SELECT" we transit from our start state to the "SELECT" state. and after that there are three options

  1. Reading nothing
  2. Reading DISTINCT
  3. Reading ALL

All of these inputs cause the state to move a new state, reading column list. In the column list, you can see that you have two options,

  1. Read one Column name and then move on
  2. Read one column name and after that read a comma, which causes you get back to "result-column" state.

The latter state prevents you from ending up like:

SELECT Name, FROM Students

It forces you to enter another column name after each comma.

I won't go in details for other parts of the diagram since @DamienBlack has already declared it well enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top