Version 22.7 of SSMS has some interesting features added. Two that are certainly worth looking into are T-SQL formatting, and schema comparison.
T-SQL Formatting:
One of the features is the ability to format your T-SQL code. This feature is marked as being In Preview, but it seems to work pretty well to me.
You can either right-click in the query editor and select ‘Format SQL’, or you can use the shortcut Control + K and Control + Q, or from the Menu bar select Edit, then Advanced, then Format SQL.
You can also adjust some of the rules that the formatter uses, to get the standard to fit your preferences.
On the Menu bar go to Tools, then Options. In the left pane, find SQL Formatter. Here you can select or deselect options that the formatter will use. I like to include semicolons after each statement, so I’ve checked the option to Include Semicolons.
In the Formatting section, there’s an option ‘Format on save’. Enabling this option will run the formatter when you save your SQL script.
There’s a button at the top of the editor labeled ‘Edit user settings as JSON’. You can use this JSON to send your settings to other people, if you want to set a standard format for the team.
There’s more information available on the T-SQL formatting feature at the Microsoft site.
Schema Comparison:
Another interesting feature added is for schema comparisons. You can compare databases, database projects, or .dacpac files. This feature is also marked as being in preview.
If you’ve used Visual Studio and Database Projects, the functionality is similar to the comparison tool used there.
To start a comparison, you can bring up the screen for the Menu bar: Tools, Schema Compare.
You’ll see inputs for Source and Target. The comparison will run to outline the steps that it will take to update the Target to have the same schema as the Source database.
Next to each of the Source and Target displays is a box with an ellipses. Click that, and you’ll see options for Database, .dacpac, and Database Project. I’ll select Database. This will bring up a connection modal, use this to connect to the database that you want to use.
You can click on Options to set or deselect the object types to include in the comparison, as well as set other options for the compare, like if keyword casing should count as a difference.
Once you’ll selected a Source and a Target, click ‘Compare’ to start the schema comparison.
Once the comparison has completed, you’ll see a list of the operations needed to bring the Target into alignment. You can uncheck an item to exclude it.
You can then click Apply to make the changes to the Target database, or click Generate Script to get a T-SQL script with all of the changes.
If you think that you’ll want to rerun the comparison, you can save your setup as .scmp file, and open it again in a future session.
There’s more information available on the T-SQL formatting feature at the Microsoft site.
Wrap-up:
Both of these functions seem very useful to me, I’ve relied on tools outside of SQL Server for this functionality. Both features are in preview mode, so I’m sure there are more improvements to come. But this looks to be a great start for both.