Using the SQL Statement Library

Objective

After completing this lesson, you will be able to use SQL Statement Library to store and run SQL statements.

Using the SQL Statement Library

Over time a database administrator creates a collection of useful and frequently used SQL statements, these personal SQL statements can be stored in and executed from the SQL Statement Library. In the SQL Statement Library SAP also provides some useful generic SQL statements.

Automatically Format the SQL Code

When writing complex SQL statements to perform a specific task, formatting it to be easy to read has mostly not the highest priority. Making the SQL code easy to read makes the code better understandable for other peoples. In modern editors there is no need to manually format the spacing, tabs and order of the SQL statement, this can be done automatically.

The image show how to use the Format Code button to automatically format you SQL statements for better readability.

Use the Format Code (1) button, to automatically formats your SQL statement code in easy readable layout.

The example shows a complex unformatted multi-step SQL statement that is difficult to read and understand. Using the Format Code button the SQL statement is formatted following the industry standard SQL Style Guidelines which makes the code better readable (2).

Save Frequently Used SQL Statements

Within the SQL Console Editor, there is the option to save your current SQL statement in the SQL Statement Library. This will allow you to later open up this same SQL statement and run it again. This is useful for SQL statements which are frequently run on an ad-hoc basis.

The image shows how to save your SQL statement in the SQL Statement Library.

Use the Save (1) button within the SQL Console Editor to store the SQL statement for future use. Provide a useful Name (2) and a clear functionality Description to make sure that the SQL statement is easy to find in the future.

When saving a given SQL statement, you can view previously saved SQL statements (3) along with their descriptions. Clicking on one will populate the name and description fields. Upon saving, the system will prompt you to confirm whether you want to overwrite the existing SQL statement with the same name.

Using the Statement Library

After saving your SQL statement and closing the SQL Editor, you can reopen the SQL statement from the Statement Library.

The image shows the SQL Statement Library with the user defined and SAP provided SQL Statements.

To open the Statement Library, select the Library (1) button in the top corner, next to the Editor button.

In the Statement Library screen, the user's saved SQL statements (2) are easily accessible at the top of the list. You can select a single checkbox for one SQL statement or multi-select them. All the SQL statements (3) with the source System are provided by SAP, and can be used by you as well.

The statement library comes preinstalled with a set of system-defined statements that are provided by SAP. All these SAP delivered statements can be found n the SQL Statement Collection for SAP HANA.

Note

For the newest SQL Statement Collection file, see SAP Note 1969700: SQL statement collection for SAP HANA.

For the SQL statement collection documentation, see SAP Note 1999993: How-To: Interpreting SAP HANA Mini Check Results.

The SQL statements are saved under your user account and are not accessible to other users.