The solution would be to lay out a set of principles for the entire team. The code would represent a mixture of rules in one project. This is not bad if you are only working on your own projects, but what if you are working along with other co-workers? Working in a team would be problematic if every programmer were to write code using their own individual style. They have experience in programming and follow rules that are convenient for them. Some SQL programmers have individual styles and preferences for formatting SQL queries. There are different ways to approach formatting code. OK, now you understand why formatting SQL code might be a good idea. Proper formatting of SQL code helps programmers avoid errors. The second query is completely different, even though it is exactly the same code-it is easy to read, it would be easy to correct the code, and it would be straightforward to compare with other well-formatted code. If you would like to compare this query to another similar query, it would not be an easy task. Aside from this, it is also a problem to make changes in this code fast. Of course it is obvious that the first query is not very easy to read. Now compare that with the formatted query below, which is the same code:ĭo you see the difference? Which is more readable? Which query is easier to understand? This SQL query above has been written without using any formatting rules. SELECT id, FirstName, LASTNAME,c.nAme FROM people p left JOIN cities AS c on c.id=p.cityid If you think formatting is something that can be safely ignored, look at the code below: Why is it Worthwhile to Format SQL Code?īeginner SQL programmers often don't pay much attention to formatting their code. In this article I discuss why this is so important and what are the basic rules you should follow. Best practices for writing professional SQL code require good formatting skills. Writing queries to a database requires knowledge about SQL syntax, but this is not all you should know.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |