Configure the SQL code style
Enable the Database Tools and SQL plugin
This functionality relies on the Database Tools and SQL plugin, which is bundled and enabled in PhpStorm by default. If the relevant features aren't available, make sure that you didn't disable the plugin.
Press Ctrl+Alt+S to open the IDE settings and then select
.Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.
You can apply and customize the SQL code style that satisfies code guidelines of your company.
To see the description of SQL style options, refer to Code Style. SQL.
Change code style settings
Customize formatting rules for the SQL code: alignment, wrapping, and indentation.
Open settings by pressing Ctrl+Alt+S and navigate to
.Expand the SQL node and select a dialect.
Select all the necessary code style settings on the available tabs.
Click Apply.
Create a code style for a dialect
Open settings by pressing Ctrl+Alt+S and navigate to
.Expand the SQL node and select a dialect.
Click the Show Scheme Actions icon (), and select Duplicate.
Type a name for a new style, and press Enter.
Select all the necessary code style settings, and click Apply.
Configure code styles per data source
After you created a style for a dialect, you can apply this style to the data source that uses this dialect.
Right-click a data source and select Properties.
Click the Options tab.
In the Code style drop-down menu, select a style that you want to apply.
Click Apply.
Apply a code style in the editor
Right-click any area or a selection of code in the editor and select Reformat Code. Alternatively, press Ctrl+Alt+L.
Import code style settings
Open settings by pressing Ctrl+Alt+S and navigate to
.Expand the SQL node and select a dialect.
Click the Set from link and select the style that you want to import.
You can select preconfigured styles like Modern, Joe Celko, Allman (DDL only)), Whitesmiths (DDL only)), Egypt, Old Idea. Or, import settings from the dialect that you configured.
Apply code style to the Generic dialect
Open settings by pressing Ctrl+Alt+S and navigate to
.Clear the Inherit general SQL style checkbox.
Apply code style settings. For more information about code style settings, refer to Code Style. SQL.
Apply the original case from the declaration
PhpStorm can format names of variables, procedures, and functions as you defined them initially. For example, if you defined the get_Amount
function in the CREATE PACKAGE statement, you want the same case throughout your code, not GET_AMOUNT
or get_amount
.
To apply this case throughout the file, PhpStorm must find the declaration of these variables, procedures, and functions (for example, in the CREATE PACKAGE statement). To apply the case in multiple files, create a DDL data source from these files.
Apply the declaration case for a file
Open settings by pressing Ctrl+Alt+S and navigate to
.Select the dialect in which you want to apply the original case from the declaration.
Click the Case tab and select the Use original case checkbox.
Click OK.
Click
or press Ctrl+Alt+L.On the following image, you can see Pack_1.sql and Pack_2.sql with identical code. Pack_1.sql is not reformatted. Pack_2.sql was reformatted with the Use original case checkbox enabled. In Pack_2.sql, the case from the package declaration was applied throughout the whole file.
Apply the declaration case in multiple files
Create a DDL data source from the files for which you want to apply the declaration case.
Open settings by pressing Ctrl+Alt+S and navigate to
.Select the dialect in which you want to apply the declaration case settings.
Click the Case tab and select the Use original case checkbox .
Click OK.
Click
or press Ctrl+Alt+L to apply the declaration case in any file of the DDL data source.