![]() ![]() See my articles, Refactoring a SQL Batch or Object with SQL Prompt and Database Refactoring with SQL Prompt for more on these topics. SQL Prompt can also perform ‘heavyweight’ refactoring processes that require a separate window or wizard to accomplish, such as renaming objects or splitting tables, or encapsulating code as a stored procedure. This article is about the ‘lightweight’ refactoring actions. ![]() SQL Refactoring ‘lightweight’ refactoring changes that do alter the text of the query, though without affecting the meaning or intent of the code.Having set that style as “active”, we apply those style options to the selected code using Format SQL ( Ctrl K+Y). We save our preferred formatting options as a code formatting style. If we were to remove all formatting from a piece of code, it would continue to function exactly as before. We lay out all the clauses, expressions, lists and parentheses in our code by adding or removing carriage returns, linefeeds, tabs and spaces. SQL Formatting changes are purely ‘decorative’ they affect only whitespace.When laying out code using SQL Prompt, by running the Format SQL command, we can apply two distinct types of changes to the code: formatting and refactoring. Standardizing the use of aliases – promotes consistency and readability and so makes code much easier to reviewįortunately, SQL Prompt actions helps each developer enforce these simple best practices or SQL Code with a few mouse clicks.Removing unnecessary square brackets from SQL scripts – will make them much easier to read.Avoiding use of select * – this will prevent unnecessary network load, query performance issues, and avoid problems caused by the column order changing, when inserting into a table.Qualifying SQL Server object names – by qualifying an object to its schema, you remove ambiguity and promote execution plan reuse.When writing SQL code, there are a few simple, but good, habits you can adopt to help improve the overall quality of your SQL code, in subtle but meaningful ways. For example, This is a guest post from Louis Davidson. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |