Overview
You will learn
- How to open a SQL console, specify the credentials, and set the current schema
- An overview of the functionality provided in the SQL console
Prerequisites
Prerequisites
- You have completed the first 3 tutorials in this group
- You have completed this tutorial which creates a database schema for an SAP HANA Cloud, data lake Relational Engine
Steps
This step demonstrates how a SQL console can quickly be opened from within SAP HANA Cloud Central and how to change the SQL console’s credentials and schema.
In SAP HANA Cloud Central open a SQL console by selecting SQL Console in the left pane. Notice that the SQL console is not associated with a database when opened in this way.

open SQL console Additional SQL consoles can also be opened by selecting the + icon.
This time select Instances, select a database, and choose Open SQL Console from the actions menu.

open SQL console from an instance Notice that it is now connected to the instance named
HC_HDBas shown by the name of the tab and the connection label or through the below SQL.SQLSELECT CURRENT_USER FROM DUMMY;
SQL console connected to HC_HDB There are several ways to connect to a database as a different user:
From the Instances list: Click the three dots next to the instance and select Sign in with Different User. Enter the username and password for the user you wish to connect with.

Change credentials in instances From the SQL console Connect menu: Select the Connected to link, click the Connect … button, and provide the new username and password.

Change credentials The Enter Credentials dialog will then ask for the new credentials to be used.

change credentials Using SQL: Run the
CONNECTstatement to switch users within the current console session.SQLCONNECT USER1 PASSWORD Password1; SELECT CURRENT_USER FROM DUMMY;
Change credentials using SQL The SQL to view the current user for a data lake Relational Engine is shown below.
SQLSELECT CURRENT USER;
Show current user for a data lake Relational Engine
The Connect menu and SQL
CONNECTstatement are session-scoped — after a disconnect and reconnect, the console reverts to the credentials it was originally opened with.If you need to alter the credentials for a database user, there are two ways to do this:
Using the SQL console: Run the following statement, replacing the placeholders with the target username and new password.
SQLALTER USER <user_name> PASSWORD <new_password>;Using the SAP HANA Cloud Central UI: Open the instance, go to the Overview tab, and scroll down to User and Authorization Management. Select Users, click on the user you want to update, and choose Edit to make your changes.

Changing user credentials using the UI The current schema can be set and viewed for a SAP HANA database using the SQL statements below or by clicking on the Current Schema link.
SQLSET SCHEMA HOTELS; SELECT CURRENT_SCHEMA, CURRENT_USER FROM DUMMY;
Set the schema For data lake Relational Engine instances, the current schema can be set and viewed as shown below.
SQLSET SCHEMA HOTELS; SELECT CURRENT SCHEMA, CURRENT USER;
Set the schema of a data lake Relational Engine
This step demonstrates how to execute a SQL query, examine the statement help, view the query results, and history tab within a SQL console.
Execute the following SQL statements.
SQLSELECT * FROM HOTELS.CUSTOMER; SELECT * FROM NON_EXISTENT_TABLE; SELECT * FROM NON_EXISTENT_TABLE2; SELECT * FROM HOTELS.HOTEL_ROOMS_VIEW;The following error dialog appears. Select Skip All.

SQL execution error dialog Notice that there is an error marker beside the lines that could not be executed. Pressing Alt+E will display further details and advances to the next error when pressed more than once.

SQL results Notice that two result tabs are shown, one for each SQL statement that generated a result.
Results can be downloaded as shown below.

Download results Options are provided on how to format the data.

Download options Rows can also be selected and then copied to the clipboard by pressing Ctrl+C.

Copy results Place the cursor on line four and open the Syntax Help panel.

Statement help panel Notice that for SAP HANA Cloud, SAP HANA databases, links to the related documentation and details on the objects used in the SQL statement are shown including a link which will open the database objects app where additional details of the object can be viewed.
SQLSELECT TOP 7 COUNT(*) AS NUM_OF_TABLES, SCHEMA_NAME FROM M_TABLES WHERE SCHEMA_NAME != 'SYS' GROUP BY SCHEMA_NAME ORDER BY NUM_OF_TABLES DESC;Commonly used shortcut keys are listed below. Try a few of them out.
Action Shortcut Add Comment Block Ctrl+Shift+/ Comment/Uncomment Line Ctrl+/ To Uppercase Ctrl+U To Lowercase Ctrl+Shift+U Go to Next Error Alt+E Go to Previous Error Alt+Shift+E Go to Line Ctrl+L Jump to Matching Brackets Ctrl+P Run All F8 Run Statement F9 Text Completion Ctrl+Space Save to statement library Ctrl+S Move Tab Left Ctrl+Shift+< (less than sign) Move Tab Right Ctrl+Shift+> (greater than sign) The shortcut keys may vary depending on the OS and browser used.
For the complete list see Common Keyboard Shortcuts for the SQL Console.
Examine the History tab.

History tab Notice details for each executed statement are displayed, including metrics such as memory consumption. Statements can be quickly located using the search functionality. Selected statements may be inserted back into the SQL console or copied for further use.
The columns can also be changed by selecting the gear icon in the right corner.

History tab columns Examine the SQL Console Settings.

Connection settings Execute the following SQL which is used to illustrate the result behavior settings.
SQLSELECT * FROM M_SYSTEM_INFORMATION_STATEMENTS; SELECT COUNT(*) FROM SYS.TABLE_COLUMNS; SELECT * FROM TABLE_COLUMNS;Double click on a cell to open the viewer. Notice that only the first 1024 bytes from the column STATEMENT are displayed in the results view for the Blocked Transactions row.

Limit for large objects Notice that over 6000 rows are in TABLE_COLUMNS.

One thousand row limit The first 1000 are displayed.

One thousand row limit These limits can be adjusted in the result behavior settings shown below.

Result behavior settings
Execute the following SQL which is used to illustrate the result display settings.
SQLSELECT CURRENT_DATE, CURRENT_TIMESTAMP(7), RAND() * 10 FROM DUMMY;The below is the result when this setting is disabled.

No formatting Enable Result Format Settings in the settings.

Format settings The below is the result when this setting is enabled.

Result formatted The overall theme for SAP HANA Cloud Central can be set in the settings which also affects the theme of the SQL console.

Theme Execute the following SQL statements.
SELECT HEXTOBIN ('48656C6C6F20776F726C64') BINARY_EXAMPLE FROM DUMMY;
SELECT '{
"name":"John",
"age":30,
"cars": {
"car1":"Ford",
"car2":"BMW",
"car3":"Fiat"
}
}' AS JSON_EXAMPLE
FROM DUMMY;
SELECT '<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>
Light Belgian waffles covered with strawberries and whipped cream
</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>
Thick slices made from our homemade sourdough bread
</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>
Two eggs, bacon or sausage, toast, and our ever-popular hash browns
</description>
<calories>950</calories>
</food>
</breakfast_menu>' XML_EXAMPLE FROM DUMMYDouble tapping on a result will open a result viewer.

The Auto-save contents of SQL consoles setting can be used to persist the open SQL console tabs and their contents. This setting is on by default.

Auto save SQL statements can also be executed in the background. This allows users to start a long-running statement, disconnect, and return later to view the results.
Execute the following statement by clicking the Run dropdown menu and selecting Run Statement in Background:
DO BEGIN
--Wait for a few SECONDS
USING SQLSCRIPT_SYNC AS SYNCLIB;
CALL SYNCLIB:SLEEP_SECONDS(3); --runs for longer than 3 SECONDS
--Now execute a query
SELECT * FROM M_TABLES;
END
The results will appear in the Background Statements tab at the bottom on the console.
The actions menu for a SQL console tab offers additional options such as the ability to rename a tab, to move a tab, to open a previously closed tab, or to search through the content of all open SQL console tabs.

SQL console actions menu 
Search through tabs
The statement library is a convenient location in the SQL console to store and retrieve frequently executed SQL statements. It provides a place to store statements that are used frequently as to not type them in repeatedly.
The library is pre-populated with useful statements called ‘SYSTEM’ statements.

You may also define custom statements that are only available to you. These are ‘USER’ statements.
/*
[DESCRIPTION]
- Future guest check-ins across all hotels
*/
SELECT * FROM RESERVATION
WHERE ARRIVAL >= CURRENT_DATE;Save your custom statement, add a name and an optional description.

Create user statement Set the name to
All Future Check-ins.
Save statement View your custom statement in the statement library

View user statements To run a statement, select one from the statement library and click the Run button.

Run saved statement If you select multiple saved statements, you additionally have the option to open them together in one tab or in individual tabs.
It is also possible to export and import SQL statements directly to/from the file system

Import or export statements Files can then be shared using a version control system such as git.
User-defined statements can be edited. From the Statement library, select the desired statement, click open, and make the desired changes. Select Save to overwrite the previous statement.

Modify saved statements
The SQL console also provides GenAI tools that assist with creating, understanding, and optimizing SQL statements. To enable GenAI in the SQL console, refer to the following Using Gen AI in SAP HANA Cloud Central.
By selecting SQL text and clicking Generate SQL From Natural Language from the Run dropdown menu, users can generate SQL statements from natural-language instructions, and also provides an explanation. Execute the following prompt.
CodeList all the column store tables and their columns in the schema HOTELS
Run prompt To understand an existing query, select the SQL statement and click Explain SQL Statement using AI from the same menu. This returns a clear natural-language explanation of what the query does.
SQLSELECT t.SCHEMA_NAME, t.TABLE_NAME, c.COLUMN_NAME FROM SYS.TABLES AS t JOIN SYS.TABLE_COLUMNS AS c ON t.SCHEMA_NAME = c.SCHEMA_NAME AND t.TABLE_NAME = c.TABLE_NAME ORDER BY t.SCHEMA_NAME, t.TABLE_NAME, c.POSITION;
Explain AI To improve a query, select the SQL statement and click Optimize SQL Statement using AI. The system will suggest a refined version of the query, often improving readability and performance.
SQLSELECT TABLES.SCHEMA_NAME, TABLES.TABLE_NAME, TABLE_COLUMNS.COLUMN_NAME FROM TABLE_COLUMNS INNER JOIN TABLES ON TABLE_COLUMNS.TABLE_NAME = TABLES.TABLE_NAME;
Optimize AI
Congratulations! You have now used the SQL console in SAP HANA Cloud Central and have become familiar with some of the features it provides.
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.