|
| 1 | +--- |
| 2 | +parser: v2 |
| 3 | +auto_validation: true |
| 4 | +time: 10 |
| 5 | +tags: [tutorial>beginner, software-product-function>sap-hana-cloud--sap-hana-database, software-product-function>sap-hana-cloud--data-lake] |
| 6 | +primary_tag: software-product>sap-hana-cloud |
| 7 | +--- |
| 8 | + |
| 9 | +# Query databases using the SQL Console in SAP HANA Cloud Central |
| 10 | +<!-- description --> Learn how the SQL Console can be used within SAP HANA Cloud Central to quickly query a selected database. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | +- An SAP HANA Cloud database |
| 14 | +- You have completed [this](hana-dbx-create-schema) tutorial which creates a database schema for an SAP HANA Cloud, SAP HANA database. |
| 15 | +- You have completed [this](hana-cloud-dl-clients-overview) tutorial which creates a database schema for an SAP HANA Cloud, data lake Relational Engine |
| 16 | + |
| 17 | +## You will learn |
| 18 | + - How to open a SQL Console, specify the credentials, and set the current schema |
| 19 | + - An overview of the functionality provided in the SQL Console |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +### Open a SQL Console |
| 24 | +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. |
| 25 | + |
| 26 | +1. 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. |
| 27 | + |
| 28 | +  |
| 29 | + |
| 30 | + >Additional SQL Consoles can also be opened by selecting the **+** icon. |
| 31 | +
|
| 32 | +2. This time select **Instances**, select a database, and choose **Open SQL Console** from the actions menu. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | + Notice that it is now connected to the instance named `HC_HDB`. |
| 37 | + |
| 38 | +  |
| 39 | + |
| 40 | + >The currently connected user can be seen by executing the SQL statement below. |
| 41 | +
|
| 42 | + >```SQL |
| 43 | + >SELECT CURRENT_USER FROM DUMMY; |
| 44 | + >``` |
| 45 | +
|
| 46 | +3. If you wish to connect to the database using a different set of credentials, select the **Connect this SQL console to a different instance** icon, select the current database and uncheck **Use cached credentials if possible**. |
| 47 | +
|
| 48 | +  |
| 49 | +
|
| 50 | + The Enter Credentials dialog will then ask for the new credentials to be used. |
| 51 | +
|
| 52 | +  |
| 53 | +
|
| 54 | + You can also use the following SQL to view and change the connected user. |
| 55 | +
|
| 56 | + ```SQL |
| 57 | + CONNECT USER1 PASSWORD Password1; |
| 58 | + SELECT CURRENT_USER FROM DUMMY; |
| 59 | + ``` |
| 60 | +
|
| 61 | +  |
| 62 | +
|
| 63 | +4. The current schema can be set and viewed using the SQL statements below. |
| 64 | +
|
| 65 | + ```SQL |
| 66 | + SET SCHEMA HOTEL; |
| 67 | + SELECT CURRENT_SCHEMA FROM DUMMY; |
| 68 | + ``` |
| 69 | +
|
| 70 | +  |
| 71 | +
|
| 72 | + For data lake Relational Engine instances, the current schema can be set and viewed as shown below. |
| 73 | +
|
| 74 | + ```SQL |
| 75 | + SET SCHEMA HOTEL; |
| 76 | + SELECT CURRENT SCHEMA; |
| 77 | + ``` |
| 78 | +
|
| 79 | +  |
| 80 | +
|
| 81 | +
|
| 82 | +### Execute SQL |
| 83 | +This step demonstrates how to execute a SQL query and view query results, messages, and history within a SQL Console. |
| 84 | +
|
| 85 | +1. Execute the following SQL statements. |
| 86 | +
|
| 87 | + ```SQL |
| 88 | + SELECT * FROM CUSTOMER; |
| 89 | + SELECT * FROM HOTEL.HOTEL_ROOMS_VIEW; |
| 90 | + SELECT * FROM NON_EXISTENT_TABLE; |
| 91 | + ``` |
| 92 | +
|
| 93 | +  |
| 94 | +
|
| 95 | + Notice that two result tabs are shown, one for each SQL statement. |
| 96 | +
|
| 97 | +2. Place the cursor on line two and open the **Statement Help** panel. |
| 98 | +
|
| 99 | +  |
| 100 | +
|
| 101 | + 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. |
| 102 | +
|
| 103 | +3. Examine the **Messages** tab. |
| 104 | +
|
| 105 | +  |
| 106 | +
|
| 107 | + Notice that details of the statements executed are shown including metrics information such as the amount of memory consumed. |
| 108 | +
|
| 109 | +4. Examine the **History** tab. |
| 110 | +
|
| 111 | +  |
| 112 | +
|
| 113 | + Notice that the statements can be located using a search and that a selected item can be inserted back into the SQL Console or copied. |
| 114 | +
|
| 115 | + >The history is not persisted across browser reloads. |
| 116 | +
|
| 117 | +### A few things to note |
| 118 | +The SQL Console within SAP HANA Cloud Central appears similar to the one within the SAP HANA database explorer but there are some differences. |
| 119 | +
|
| 120 | +* Opening the SQL Console within the SAP HANA Cloud Central can be done much quicker than opening the full SAP HANA database explorer. |
| 121 | +
|
| 122 | +* The SQL Console that you access from within SAP HANA Cloud Central can only connect to databases that are within the same BTP subaccount as SAP HANA Cloud Central. |
| 123 | +
|
| 124 | +* The SAP HANA database explorer has some additional functionality |
| 125 | +
|
| 126 | + * Persistency of SQL tabs and their contents |
| 127 | + * SQL debugging |
| 128 | + * SQL parsing to detect potential errors |
| 129 | + * Code completion of schema objects |
| 130 | + * SQL formatting |
| 131 | + * SQL viewers for HTML, XML, JSON, binary, and spatial |
| 132 | + * Results can be downloaded in a CSV |
| 133 | + * Ability to run statements in the background |
| 134 | + * Ability to run statements against multiple instances |
| 135 | + * Generate SQL Analyzer file or explain plan |
| 136 | + * Statement library |
| 137 | + * SQL Console settings |
| 138 | +
|
| 139 | +### Knowledge check |
| 140 | +
|
| 141 | +Congratulations! You have now used the SQL Console in SAP HANA Cloud Central and have become familiar with some of the features it provides. |
0 commit comments