Find your perfect database development style with Rider
Rider contains many features for styling code so that it’s easy to read, and therefore easy to understand and maintain that code.
This post is part of a series around finding a coding style that fits you like a glove, and how Rider can help:
- Find your perfect coding style using Rider
- Find your perfect C# style using Rider
- Find your perfect database development style using Rider
- Find your perfect web development style using Rider
In this post, we’ll look at how you can create a style that works for all your database programming. For the purposes of this post, we’ll focus on Microsoft SQL server, though the styles can be applied to any query language.
Database maintenance and query languages have their own way of doing things that is different than general purpose languages. To start, most query languages are declarative and are often considered to be a DSL (domain specific language). This means how we read and write SQL can be a bit different than how we’d write a procedural, object-oriented, functional, or other type of language.
Make the case for great SQL style
SQL languages tend to be case-insensitive. But database developers and DBAs have traditionally distinguished keywords, types, identifiers, and object names with specific capitalizations. This makes SQL immensely more readable, as your eyes can easily pick out the main points of what’s going on in a block of code.
A popular notation is to capitalize keywords, however, object name style and capitalization can vary from team to team. Customizing capitalization in Rider is easily done in the Preferences/Options | Editor | Code Style | [SQL Language] | Case.
Related to casing and capitalization in SQL is the notion of quoted identifiers. Quoting an identifier is important when you have a database structure that requires fully qualified naming syntax. This is often caused from a database that contains objects with modern names, such as a table name with spaces – for example, an [Order Details] table.
Other times, databases use multiple schemas that need to be distinguished with a fully-qualified name. Rather than typing in quotes for identifiers in SQL statements, configure the identifiers alongside the capitalization in Preferences/Options.
Define your DDL’s style
DDL (Data Definition Language) is a specific subset of SQL commands that are meant for creating and managing database objects such as databases, tables, stored procedures, triggers, views, logins, and more. Styles for DDL tend to be similar to query command styles.
Rider contains a tab in the Code Style settings targeting DDL commands for all SQL dialects it supports. DDL code isn’t just for creating objects though – it can be used as supplemental documentation to the code base. A quick skim through some DDL can reveal what constraints a table contains, object access security, or even whether client code should access a stored procedure or view rather than direct table access. That is, if the DDL is easy to read. Easy to read means the code is styled and formatted well.
Stylish SQL expressions
Querying data often involves imperative code expressions, such as branching and switching statements. Without it, data would come in a raw, tabular format that requires manipulation in the app’s code instead.
Fortunately, Rider contains several style preferences for expressions in SQL languages, including spacing options around and inside of parentheses, and the alignment of keywords such as
ELSE. Alignment is a huge part of style, and quite important for readability in SQL. Just use Ctrl+Alt+L | Cmd-Alt-L to reformat existing code.
That’s why Rider has so many options regarding alignment and wrapping. Specific statements such as
SELECT all have entire sections dedicated to their syntax and style.
Rider allows you to customize all the settings necessary to style your SQL code just perfectly.
Download Rider today and let us know what styles you love to use.
Subscribe to Blog updates
Thanks, we've got you!
Eager, Lazy and Explicit Loading with Entity Framework Core
Entity Framework Core (EF Core) supports a number of ways to load related data. There’s eager loading, lazy loading, and explicit loading. Each of these approaches have their own advantages and drawbacks. In this post, let’s have a quick look at each of these ways to load data for navigational prope…
OSS Power-Ups: bUnit – Webinar Recording
The recording of our webinar, OSS Power-Ups: bUnit, with Egil Hansen and Steven Giesel, is available. This was the twelfth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webi…
Accelerating Your Testing Workflow with Unit Test Creation and Navigation
Unit tests play an important role in our daily development workflow. They help us ensure our codebase's correctness when writing new functionality or performing refactorings to improve readability and maintainability. In the process, we often create new test files that accompany the p…
Introducing Predictive Debugging: A Game-Changing Look into the Future
With the introduction of debugging tools, software developers were empowered to interactively investigate the control flow of software programs to find bugs in live environments. At JetBrains, we've always strived to improve the art of debugging. Besides the more standard things you expect from a de…