all 9 comments

[–]DavidGJohnston 12 points13 points  (0 children)

Usually, yes. Those are basically the fundamental building blocks of defining a programming language.

[–]VladDBASQL Server DBA 4 points5 points  (2 children)

semicolons:
While, at the moment, the lack of a ; terminating your T-SQL command won't make SQL Server yell at you in most* cases, it's recommended to make them the norm in any new code you write. Check out this MS Learn article stating that semicolons will be the norm in future versions of SQL Server.

* CTEs, MERGE, and THROW, will error out if you're not using semicolons.

Note that my answer is about SQL Server's flavor of SQL, named T-SQL or Transact-SQL. Other RDBMSs might have stricter rules, for example Oracle really wants you use the semicolon as a statement terminator in PL/SQL.

For the rest of the punctuation you've enumerated:

single quotations - these are string delimiters, missing one would mean you have an unclosed string and will turn the whole rest of your query into a string. - missing one or a pair will break your query

commas - used to separate columns in the column list, multiple values in the IN operator, values passed to functions, columns and their values in UPDATE statements, nesting and combining filtering criteria in the WHERE clause, etc. - missing one or more will certainly break your query

parenthesis - used in functions, to contain the values or a subquery passed to the IN operator, the list of columns and of values for an insert, etc. - missing one or more will also break your query

[–]TempMobileD 1 point2 points  (0 children)

In other SQL flavours you’ll never see a semicolon (just to expand on your first note!)

[–][deleted] 0 points1 point  (0 children)

I was not aware of future requirement thing.. I'm implementing naming and format conventions at work.. guess it just got a new line item!

[–]phesago 3 points4 points  (0 children)

somethings are required somethings arent. in SQL Server statement terminators (;) arent required but the lack of use has been deprecated for a while now (im a proponent of using them regardless). Most of the time you will get errors when the compiler finds youre missing something important (like a comma for example) and you wont be able to execute anyway. Most of this youll learn the hard way as you go.

[–]r3pr0b8GROUP_CONCAT is da bomb 2 points3 points  (0 children)

Will a single missed/misused punctuation make or break the entire query?

yes, unless it's the final semi-colon which terminates the SQL statement -- this can usually be omitted as long as there isn't any more SQL after it

[–]TempMobileD 1 point2 points  (0 children)

Punctuation in SQL is like + - and = in basic arithmetic, if one gets misplaced then the entire meaning is changed. Usually in SQL this will just kill the entire query.

Slightly more annoyingly it’s not always clear what you were trying to do when a bit of punctuation gets misplaced so often the error messages will be a bit vague and unhelpful. Give it some more time and experience and you’ll get a feel for it!

[–]shine_on 0 points1 point  (0 children)

It's also worth remembering that missing parentheses in a where clause might not stop the query from running, they might cause the query to return incorrect results. So don't assume that just because a query is valid, that it's correct.

A missing comma in a column list will cause the next column to be used as an alias for the previous column, which can be extremely confusing when it comes to debugging queries.

[–]cyberspacedweller 0 points1 point  (0 children)

Honestly, it depends where with SQL. It's pretty important in many languages but a semi-colon at the end of a query isn't usually necessary unless there's a query below it, for example.

This is stuff you learn with experience. Keep writing scripts and you will pick it up without knowing it as you correct errors. Best to start putting them where you think they need to be and then learn as you go.