Guest postThis is a guest post from Louis Davidson. Louis is a senior data architect for the Christian Broadcasting Network in Virginia Beach.
A highly experienced Microsoft SQL Server MVP, he speaks at most PASS conferences and a large number of SQL Saturday events.He regularly contributes articles to both his own and, and has written a book on database design for each of the last five major releases of Microsoft SQL Server.With ten programmers working on the same project, how do you agree on a standard style for formatting SQL code, and then implement it consistently? SELECT StateProvinceName StateName, Cities.LatestRecordedPopulation, SalesTerritory FROM Application.Cities JOIN Application.StateProvinces ON StateProvinces.StateProvinceID=Cities.StateProvinceID WHERE CityName='Nashville' ORDER BY LatestRecordedPopulation descListing 1We apply formatting by invoking the Format SQL command, from the SQL Prompt menu, or from the context menu opened by right-clicking in the query window, or via the Ctrl + K then Ctrl + Y keyboard shortcut. When we run this command, SQL Prompt will apply to the code all the style options associated with the active formatting style (in this case the pre-installed Redgate Default style), plus any activated formatting actions (covered shortly).Listing 2 shows the resulting, formatted code:Listing 2As you can see, this is immediately a lot more readable. It’s still not perfect, to my eyes at least (more on that in the next article), but it’s a big improvement.Let’s look at the details of this formatting.
I’m only going to review them briefly, as they are covered in detail. The formatting stylesSQL Prompt allows us to define styles, where each style (akin to a template), encapsulates a specified set of values for options that govern how we wish to format SQL code.
They include maps for all the West European and many East European countries (as indicated on the map). Download becker 10.0 traffic pro dtm. Becker Online Pro 4.0 Europa Navigation SoftwareNAVTEQ 4 CDs ISO RAR CD1: 462.67 MB CD2: 478.57 MB CD3: 532.68 MB CD4: 383.77 MBThese CDs are the perfect partners whilst driving in Europe for either business or pleasure. Traffic Pro/DTM Highspeed CD – V7BECKER DTM HIGH SPEED 7910 / 7913 / 7918These CDs are your navigation partner of choice whilst driving in Europe for either business or pleasure. Traffic Pro/DTM Highspeed CD – V7BECKER DTM HIGH SPEED 7910 / 7913 / 7918These CDs are your navigation partner of choice whilst driving in Europe for either business or pleasure. It covers a total of 7.39 million kms of roads and over 1.2 million Points of Interest.
Compare Redgate SQL Compare vs Toad for Oracle. 118 verified user reviews and ratings of features, pros, cons, pricing, support and more. By default, SQL Prompt loads suggestions for all databases specified in a query. However, to improve the performance of SQL Prompt you might want to include/exclude certain servers, databases or schemas. To configure this: On the SQL Prompt menu, select Options. Go to the Suggestions Connections page.
From the SQL Prompt menu, select Edit formatting styles to bring up the Formatting styles dialog.Figure 1You can see five pre-defined Redgate styles, each one representing a common, different way to style SQL code, as well as a Your Styles section, which displays your own custom styles. I have just one custom style, currently, called Louis style. It’s worth checking the Preview current query checkbox, so you can preview the formatting for each style, within the formatting styles dialog, simply by clicking on it.Currently, the Redgate default style is set as the active style, so by running the Format SQL command, as previously, SQL Prompt applies all the code formatting options specified by this default style. Within the Formatting styles dialog, we can switch to a different active style simply by clicking on a different style and selecting Set as active via the vertical ellipsis.As part of the upgrade to SQL Prompt v8, from an older version, SQL Prompt will automatically convert all existing styles (.sqlpromptstyle) over to the new style (. Sqlpromptstylev2), and save them in the user’s Style folder, which by default is located at%LOCALAPPDATA%Red GateSQL Prompt 8StylesV2. They will appear automatically in the Your Styles section.How to import old styles post-upgradeWhat if another SQL Prompt user, still on an older version of the tool, sends you a style that you want to import, after you’ve already upgraded to v8?
For any custom style defined using the ‘experimental’ version of the new styles in SQL Prompt v7, locate the style, rename it with the ‘v2’ extension and copy to the style folder. For custom styles defined using the old-style format, you’ll probably want to redefine these styles from scratch, making use of the greater versatility offered by the v2 style features. However, if you do wish to auto-convert an old style, there is a roundabout manner to make this happen: ‘Downgrade’ to SQL Prompt v7, place the style in the style folder, then upgrade again to v8, at which point it will be auto-converted.Creating a new styleThere are several ways to create a new custom style. Under Your Styles, click + Create a Style to open the Create a style dialog, then name your new custom style and specify the style on which it will be based, which by default will be the Redgate Default style.Figure 2Alternatively, you can choose Copy from the vertical ellipsis next to the style on which you wish to base the custom style. Since it’s not possible to edit directly any of the pre-defined Redgate styles, if you select one of these styles and then hit Edit style, or double click on any of these styles, you’ll be prompted to create a new style, based on the selected Redgate style.Once you select Create style, or if you Edit, or simply double click, a style listed under Your Styles, you’ll open the Custom style dialog, where you can define all the style options for the selected style. The style optionsWhen you run Format SQL, SQL Prompt will apply all the style options defined for the active style, plus any of the formatting actions that are currently activated (covered in the next section).
Figure 3 shows the style options for MyCustomStyle, without making any further changes:Figure 3SQL Prompt allows us to control the layout and formatting of the various statement, clauses, and expressions that comprise a typical SQL command.For example, under Global Whitespace, SQL Prompt control over tab behavior, line wrapping, and lets you determine the number of empty lines between statements, using the New lines setting. The Statements section provides close control over how DML and DDL is formatted, as well the formatting of control flow statements such as BEGINEND blocks, CTEs and so on. We can also control the formatting of joins, and of various types of expression.You can edit these options to suit your, or your team’s, requirements and then click Save, and the new custom style will appear under Your Styles, and be set as the active style.Figure 4 The formatting actionsWithin the SQL Prompt Options dialog, the Format Styles section defines all the actions that SQL Prompt will perform, on running Format SQL.Figure 5The checked actions will be applied to any active style, when we run Format SQL. By default, it will apply casing options (as defined within the style options for the active style) and insert any missing semi-colons.
However, we can expand this to include other options such as removing or, begrudgingly, adding square brackets around identifiers, qualifying object names, and adding aliases. To return to the default settings for the formatting actions, just use the Restore defaults button in the top right of Figure 5.The observed behavior on activating some of these formatting actions, will depend on settings elsewhere. For example, the behavior of Qualify object names will depend on the settings for Inserted code Qualification.