Does every SQL statement follow this structure?

Question

In the context of this exercise, does every SQL statement follow this structure?

Answer

In general, SQL statements will usually follow a similar structure as the given example SQL statement, but depending on what you are trying to do, they can also look very different.

The following are some examples of different kinds of SQL statements you might use, which will be covered throughout this lesson.

This statement selects all rows from a table.

SELECT * FROM table;

This statement will create a new table.

CREATE TABLE students (
  column_1 data_type,
  column_2 data_type
);

This statement will update a row in a table.

UPDATE table
SET column_1 = new_value
WHERE id = 3;
9 Likes

Is there any reliable source for the assertion " Statements always end in a semicolon ;." ? I’ve been programming in (My)SQL for about 20 years now and NEVER put “;” unless I have to, in order to separate multiple commands.

17 Likes

W3schools.org’s tutorial on SQL says:

Semicolon after SQL Statements?

Some database systems require a semicolon at the end of each SQL statement.

Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.

15 Likes

Your answer does not really answer the question (but indirectly confirms my doubt and “bug report” of an incorrect statement). Indeed,
“to separate” is NOT AT ALL the same as “to end”.
Yes: “;” is standard to SEPARATE commands, but it is NOT necessary to “always end statements” as is claimed incorrectly.
I am 100% affirmative that it is not needed to end a statement in any version of MySQL, and I think it is the same in most if not all other SQL.
You just REPEAT the doubtful statement: “Some database systems require…”. Repeating something does not make it true.
I asked: “Is there any reliable reference for this?”
Can you name the “database systems” (sic) that do require it?

5 Likes

this will answer your statement .

But here after microsoft will mandatory the semicolon for every statement to end , this i read in 2020 article

2 Likes

I use sql server & never bother with the semi-colon, same as i never bother with capitals ( but the statements do look better with Capitals.
Not sure about Oracle , i heard it is necessary

This is what I believe the answer is to the below questions in the Statements topic:

Run the code to observe the results, and ask yourself:

  • Which parts of the statement are the clauses ?
  • “SELECT” and “FROM”
  • What table are we applying the command to?
  • celebs
1 Like

Thank you so much @m_f_h for bringing your thoughts and opinion man. Much appreciated.

1 Like

That’s right. i think we dont always need a semicolon specifically at the end. i just tested a statement without semicolon and surprisingly it works. Much appreciated

you like for real…no need of semicolon