Exercise Objectives
After completing this exercise, you will be able to:
- Use the SQL Console to query data from a database connection and a standard catalog schema.
- Use the SQL Console to query data from an HDI container connection.
Business Example
You would like to become familiar with the SQL Console by writing a few simple SQL statements, first on a classic database connection and then against a container.
Prerequisites
Prerequisites
- Your SAP Business Application Studio development environment should have been set up and the HC300 project imported and deployed.
- A connection to the HANA Cloud database (HC300_DB (A####) (SSO enabled)) should have been setup.
Steps
Open an SQL Console for your database connection HC300_DB (A####) (SSO enabled).
Switch to the SAP HANA Database Explorer view.
Highlight your SAP HANA classic database connection HC300_DB (A####) (SSO enabled), and then choose Open SAP HANA SQL Console on the right of the name.
Execute a query to read all data from table ORDERS in the schema TRAINING.
In the empty tab, carefully enter the code:
Code Snippet1SELECT * FROM "TRAINING"."ORDERS";Press Run (F8).
Execute a query to list only the columns STORE, PRODUCT, QUANTITY filtered by product Mouse.
Adjust the code as follows:
Code Snippet1SELECT STORE, PRODUCT, QUANTITY FROM "TRAINING"."ORDERS" where PRODUCT = 'Mouse';Press Run (F8).
Automate the generation of an SQL SELECT statement by using the provided context menu option against the table ORDERS which is located in the TRAINING schema.
In the top left pane, navigate to HC300_DB (A####) (SSO enabled)→Catalog→Tables.
In the Catalog Browser pane, choose the Apply filter icon and select Filter objects by schema. A list of schemas should appear. Select the TRAINING schema. Choose OK.
Result
You should now see the tables listed in the lower pane.In the lower left pane, right-click on the table ORDERS and choose the context menu option Generate SELECT statement.
Press F8 or choose Run on the toolbar to execute and display the data.
Notice the other options that can be used to generate common SQL statements for the chosen table, such as CREATE.
Open an SQL Console for your HDI container.
In the Database List sub-pane, highlight your HDI container and then choose Open SAP HANA SQL Console .
Caution
There are two different icons to open an SQL console connected to an HDI container. Please make sure to use the right one (Open SAP HANA SQL Console).The left one, Open SAP HANA SQL Console (Admin), is used to open an SQL console as user container_schema_name..._DT, connected to the schema <container_schema_name>#DI, which is the HDI container's API schema. So this is for HDI content administration and would not provide the necessary privileges for this exercise.
In the new console tab, check that the Current Schema corresponds to your HDI container schema name, that is, HC300_A####_HDI_DB_1.
Execute a query to read all data from table Employees.
In the empty tab, enter the code:
Notice the use of the namespace HC that prefixes the table name (this topic is covered later). If you do not include the namespace, the table is not found. In addition, when working with containers, notice that the schema does not need to be specified because the schema is already known to the container (the schema "belongs" to the container and is unique).Code Snippet1SELECT * FROM "HC::Employees"Press Run (F8).
Close all open tabs in Business Application Studio and come back to the Explorer.
Right-click any open tab and choose Close All.
Choose the Explorer icon.