Is the semicolon necessary in SQL?

semicolon indicates end of a statement, so if there are multiple statements then you should use semicolon else it will work fine.

I generally use semicolon as a practice, it can be useful even when you are running queries on sql client e.g. in Sql Developer using semicolon is very helpful if you have multiple statements on worksheet, as you can simply go to that particular statement and use F9 to execute that, without semicolon this is not possible.


It is not mandatory if you run a single query at time, it comes necessary instead if you want to run multiple query with a single command.

However in most of JDBC drivers out there it is not possible to add multiple query separated with semicolon in a single JDBC Command, it exist however the addBatch method that allow you to add multiple statements :

java.sql.Statement stmt=con.createStatement();   
stmt.addBatch(insert_query1); //insert_query1   
stmt.addBatch(insert_query2); //insert_query2  

As a rule of thumb, in JDBC semicolon is not necessary at all, if you need multiple statement use addBatch.