Let's talk about some practices we follow when writing codes. You may have noticed that some use semicolon at the end of the statement. Some do not use it at all. So the question is;
What is the purpose of having a semicolon at the end of the statement?
As per ANSI SQL-92, semicolon should be used at the end of the statement, indicating that "this is the end of the statement". Basically, it is the statement terminator. However many developers do not follow it and in many cases, SQL Server does expect it too. Because SQL Server or Management Studio does not force us to use it, we have naturally ignored it.
SQL Server requires this with some cases. This has to be used when you are using CTEs or working with Service Broker.
Once this was announced as a deprecated but hardly believable because statements like mentioned above still require it.
Now the question is, should we use it for all or just use when it is required. In my case, I always try to use it for making the statement clearer, following standards and avoid mistakes. See a funny mistake in below code. However, whether it is required or not, it is always better to stick with standards.
No comments:
Post a Comment