Learn how the SAP HANA database explorer for Visual Studio Code extension can be used to connect to both SAP HANA Cloud and on-premise databases, about related general Visual Studio Code features, how to use the catalog browser, and how to execute SQL queries. The SAP HANA database explorer for Visual Studio Code extension contains similar functionality to that in the web-based SAP HANA database explorer although not all functionality is available.
For more information about the latest features and version updates to the extension, you can refer to the CHANGELOG tab.
Install extension
Open the extension from the new icon in the activity bar (left) and navigate to the Database List.
Open extension
There are two types of connections you can make with the extension.
Local Connections are connections to an SAP HANA database (cloud or on-premise) added via the + icon.
SAP HANA Database Explorer Connections are database connections retrieved by logging into Cloud Foundry and querying for the set of connections that the Cloud Foundry, web-based SAP HANA database explorer have created.
Step 2Add a local database connection
+
The SAP HANA database explorer extension can connect to SAP HANA Cloud and on-premise databases as well as an SAP HANA User Store. In this tutorial, a connection to an SAP HANA Cloud database will be made, but the steps to connect to the other types are very similar. Adding local connections do not require authentication to the SAP Business Technology Platform (BTP) or Cloud Foundry.
Hover over the Database List section and click the + button to Add SAP HANA Database.
Add Database
A form to add a database will open.
Select SAP HANA Cloud as your database type and enter values for the Host, Port, User and Password, such as USER1 and Password1. You may also change the display name, as desired.
This tutorial uses the HOTELS schema. Set the default schema value in the Advanced Options as shown below. Subsequent SQL consoles you open will now start with this schema value.
Advanced
currentSchema=HOTELS;
Ensure that you connect the database securely using TLS/SSL by ticking the checkbox. If you do not check the Save Password checkbox, you will have to enter your password each time you start using the extension.
SAP HANA Cloud Connection
A confirmation notification will appear in the bottom right corner if your database was added successfully. The database will also be listed under Local Connections in the Database List.
Successful Connection
To edit your database connection, right click on the database connection name and select Edit Database.
Edit Database Connection
Here you can edit your values for the Host, Port, User and Password.
Edit Database Connection values
To delete your database connection, right click on the database connection name and select Delete Database. Then a pop-up will ask you to confirm the deletion.
Delete Database Connection
Then a pop-up will ask you to confirm the deletion for you database connection.
Delete Database Connection Pop Up
The SAP HANA database explorer extension also allows you to connect to the database connections you may have specified in the Cloud Foundry, web-based SAP HANA database explorer. These connections are managed by the web-based SAP HANA database explorer and cannot be edited in the extension. In order to complete this section of the tutorial, ensure that you have the Cloud Foundry CLI installed and added to your path.
Open the terminal through Visual Studio Code by navigating to Terminal > New Terminal in the Visual Studio Code.
Open Terminal
Verify and if needed set the Cloud Foundry API endpoint.
set the API Endpoint
Shell
cf api
cf api https://api.cf.us10-001.hana.ondemand.com
The API endpoint value can be obtained in the SAP BTP Cockpit as shown below.
API Endpoint
Verify that the URL is set correctly in the SAP HANA database explorer settings.
Click File > Preferences > Settings, search for SAP HANA database explorer: URL, and replace the region with the correct region for your sub-account (e.g. us10).
Find Settings
Change URL Region
Login to Cloud Foundry with the following commands.
To login with email and password:
Terminal
cf login
To login with single sign-on:
Terminal
cf login --sso
Logging in with single sign-on will require you to click on the provided link, copy the code provided, and then paste the code in the terminal by right-clicking and clicking enter.
For more login options:
Terminal
cf login -help
After pressing the refresh button you should see the same database instances list from the web-based SAP HANA database explorer (Cloud Foundry edition) appear in your Database List.
database list
To open an SAP HANA SQL console in Visual Studio Code, hover over the connection and click the console icon.
Cloud Foundry SQL console
To open the database in SAP HANA database explorer, click the stacked boxes icon.
Cloud Foundry Web
Step 3Using the Database List and Catalog Browser
+
Select Schemas to open the list of schemas in the Catalog Browser.
As you can see, since the current Schema was set to HOTELS using advanced options when adding the database, this list is already filtered for you. By hovering or clicking on the Catalog Browser section, you will see a filter icon and a refresh icon.
Click on the filter icon.
Open Schemas
This will open a list of all schemas. Selecting/deselecting all schemas will list all of the schemas in the Catalog Browser and show you all artifacts under the catalog if opened in the Catalog Browser. By selecting specific schemas, only the selected ones will be in the Catalog Browser, while also filtering other artifacts such as tables and procedures.
Filter Hotel
Clicking OK will apply your filter selections. Keep the HOTELS filter selected and click OK.
Step 4Dependency Viewer
+
Database object dependencies can be visualized using a graphical dependency viewer.
The dependency viewer can be started in two ways:
By right-clicking an object in the catalog browser and choosing “Open Dependency Viewer” from the context menu
Catalog Browser Dependency Viewer
By right-clicking a database connection.
Database Dependency Viewer
When starting the dependency viewer from an object in the catalog browser, the dependency viewer directly shows the dependencies of the selected object.
The dependencies can be explored in both directions, incoming and outgoing. Schemas are indicated as boxes surrounding the objects.Incoming and Outgoing Nodes
Schemas can be collapsed by double-clicking them to focus on the relevant dependencies. Clicking on an object highlights it and its direct dependencies for easier analysis.
When starting the dependency viewer from a database connection, it is initially empty. You can select an object to visualize via the “Select Object” dropdown.
This dropdown can also be used to switch to a different object if one was already previously selected.Select Objects from Dependency Viewer
If you want to simplify your graph, or only have specific object types visible, you can filter them using the Object Type filter by unselecting the undesired items.
Object Type Filter
Note: If you get a Database URL error message, open settings.json from C:\Users\User_Name\AppData\Roaming\Code\User and remove the line "SAP HANA Database Explorer.URL": and the following url.Edit settings.json
Step 5Visual Studio Code features
+
Learn how to change settings and leverage features such as split editor, layout toggles, and the terminal.
If you would like to change the color theme of Visual Studio Code, one way to do that is through File > Preferences > Themes > Color Theme. From here, you can select from a light or dark color theme.
change Theme
Themes List
There are also other SAP HANA Cloud database explorer settings that you can set within the Visual Studio Code settings. If you open settings by clicking Manage > Settings, and search Database Explorer, a number of settings for the extension will appear in the list. There are two specific settings to point out that could be particularly useful.
Open Settings
Max Sql Result Size: Here you can change the maximum amount of SQL results that you want to allow to be returned by any queries that you run.
Show Database Explorer Connections: By selecting/deselecting this checkbox, you can show/hide the SAP HANA Database Explorer connections in your Database List. Note that this will not affect your local connections that are only available in Visual Studio Code.
DBX Settings
Visual Studio Code also has built-in functionality that allows you to split editors which can be very useful to customize your workspace. For example, if you are working on multiple tasks, or need to refer to a table while manipulating another one, this feature can allow you to work more efficiently. In a SQL console, run the following code.
SQL
SELECT*FROMCUSTOMER;
Open another SQL console, click the split editor icon, and then drag one of the SQL console tabs into the new space to the right.
Split Editor
As you can see in the CUSTOMER table, this includes both individual customers and company customers. You want to create a new table that consists only of company customers and insert the relevant information into the new table. To do so, run the following code in the empty SQL console and verify by comparing the table results that the necessary entries were made.
Instead of a split editor, you can alternatively create a new window by dragging an open tab outside of your current window editor.
New Window Editor
Additionally, Visual Studio Code has other features to help organize your workspace. The icons in the top right corners allow you to toggle (hide/show) different parts of the workspace which you can also do by resizing and snapping different areas. Click on the second icon to toggle the panel and use the Terminal to create a new file for your SQL code.
Toggle Panel
Terminal
notepad average_rating_function
Remember where you created this file, as you will need that location later.
Create Notepad File
Paste the following code into the file and save it as a SQL file by adding .sql to the file name. This function will return the average rating of a specific destination from the TOURIST_REVIEWS table.
The extension also allows you to import and export SQL files to and from your computer. In the web application, there is a statement library where a user can store SQL files, but with the extension, SQL files that are stored on the file system can also be incorporated into GIT so that file sharing for collaborative work is easier.
Clear your SQL console, or close the current one and open a new console. Click on the folder icon to import the file you created in the previous step and open it in Visual Studio Code.
Import File
Edit the SQL in the editor by changing the INT in line 2 to FLOAT to change the function to return a more precise average.
Make Changes and Save
Click the save icon to save your changes to the SQL file on your computer.
Step 7Run SQL code
+
Open a new SQL console and use the newly created function with the following code. Click on the dropdown arrow beside Run to view the different Run options. Then, normally Run your code.
SQL
SELECTAVERAGE_RATING(1)FROMDUMMY;
Note how the Run options differ in the extension (left) from the web application (right).
Difference in Run Options
The results of running your function are shown below.
Run Function
Click on the Messages tab to see more information such as execution time and memory usage of the SQL statement(s) that you ran.
Messages Tab
If an error occurs, you will see an error message here as well.
Error Message
Clicking on the History tab will display a list of statements that you have run, along with information such as its runtime and result. You can also search through the history and paste queries into the SQL console by clicking on a statement.
History Tab
Note that certain capabilities (as listed) are only available in the web application of SAP HANA database explorer and are not currently available in the extension. A few examples are listed below:
Execute SQL on multiple databases or as a background activity
Global Search
Debugging SQLScript
Graph Views
Viewing diagnostic files in the Catalog Browser
Step 8Knowledge check
+
Congratulations! You have now used the SAP HANA database explorer extension for Visual Studio Code to create tables and functions within an SAP HANA database and have become familiar with some of the features it provides.
Share feedback on this tutorial or join the conversation in SAP Community.
Submit detailed feedbackDiscuss in Community
Steps
Step 1 of 8
1. Set up2. Add a local database connection3. Using the Database List and Catalog Browser4. Dependency Viewer5. Visual Studio Code features6. Import and export SQL code7. Run SQL code8. Knowledge check
Joule
AI Notice
Joule is an AI assistant. Generative AI may produce inaccurate, incomplete, or biased information. Always verify important details before acting on them.
Conversations are sent to SAP-hosted large language models for processing. Do not include personal data, credentials, or confidential information in your messages.
Joule's responses are based on the SAP tutorial catalog and may not reflect the latest product changes. For authoritative guidance, consult the linked tutorials and official SAP documentation.