SAP

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Create a User, Tables and Import Data Using SAP HANA HDBSQL

Use the command line tool HDBSQL to connect to a SAP HANA database, create a user, and create tables which will be used in subsequent tutorials in this mission.

Overview

You will learn

  • ✔How to connect to SAP HANA from a client machine using HDBSQL
  • ✔How to create a user, schema, tables and import data

More from Dan van Leeuwen

See all 60 tutorials by Dan van Leeuwen →

Prerequisites

  • You have completed the first 2 tutorials in this mission.

Steps

Platform: Windows macOS Linux

Intro

HDBSQL is used in this tutorial as it is part of the SAP HANA client install. HDBSQL is a basic tool for executing SQL scripts and providing an interface for interactive queries. Another option to execute SQL operations is the SQL Console that is part of SAP HANA Cloud Central or the SAP HANA database explorer which is part of an on-premise install of the SAP HANA Cockpit.


Step 1 Connect to SAP HANA using hdbsql
—

This step demonstrates how to connect to a SAP HANA instance using HDBSQL from the SAP HANA client installation.

  1. Copy and paste the following command to see the command line options and press the space bar to advance though the information.

    Shell
    hdbsql -h | more
  2. Connect to either SAP HANA Cloud or SAP HANA on-premise instance using host, port, and credentials. Details on where to find these values are covered in the third and fifth steps of the first tutorial in this mission.

    • To connect to SAP HANA Cloud, see the following general command.

      Shell
      hdbsql -n <host name>:<port> -u <user> -p <password>

      The following is a connection example for the SAP HANA Cloud. Notice that if the -p is not provided then you will be prompted to enter your password.

      Shell
      hdbsql -n 3b2gf55e-4214-4bd9-adfc-f547d8e2d384.hana.trial-us10.hanacloud.ondemand.com:443 -u DBADMIN

      Connect with hdbsql
      Connect with hdbsql

    • For SAP HANA on-premise, there are two options shown below to connect.

      Shell
      hdbsql -n <ip address>:39015 -u <user> -p <password>
      or
      hdbsql -n <ip address> -d <database name> -i <instance number> -u <user> -p <password>

      Below are two connection examples for an on-premise SAP HANA instance.

      Shell
      hdbsql -n <ip address>:39015 -u SYSTEM -p your_password
      or
      hdbsql -n <ip address> -d HXE -i 90 -u SYSTEM -p your_password

      Notice that either the host and port combination or the host, database name and instance number can be used to connect.

  3. If your connection succeeded, proceed to sub-step 4. If not, the following information may be helpful in diagnosing a failed connection.

    • The HANA Cloud instance can be configured to enable applications running from outside the SAP BTP to connect. The current setting is shown in SAP HANA Cloud Central in the screenshot below.

      Allowlist in SAP HANA Cloud
      Allowlist in SAP HANA Cloud

      An example of configuring this setting is shown in Allow connections to SAP HANA Cloud instance from selected IP addresses — using the command line.

    • The SAP HANA Cloud, HANA database free tier instance will be automatically stopped overnight. That means you need to restart your instance before working with it each new day.

    • Connections to a HANA Cloud instance must use encryption. The default encryption library on Windows is mscrypto and on Linux and macOS it is OpenSSL. The following example demonstrates how one could use the SAP provided conmmoncrypto library instead of the default encryption library. Note, the following steps require that the SAP HANA Client be downloaded from the SAP Software Downloads as the download includes the SAP Common Crypto library (libsapcrypto). Note that the environment variables can also be set by running source hdbclienv.sh or hdbclienv.bat.

Shell
mkdir ~/.ssl
# Download the public root certificate used by HANA Cloud
wget --no-check-certificate https://cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem -O ~/.ssl/DigiCertGlobalRootCA.crt.pem
# Show the command help for the sapgenpse
sapgenpse -h
# SECDIR & LD_LIBRARY_PATH environment variables are required when using the commoncrypto library
export SECUDIR=~/sap/hdbclient
export LD_LIBRARY_PATH=~/sap/hdbclient:$LD_LIBRARY_PATH
# macOS only
export DYLD_LIBRARY_PATH=~/sap/hdbclient
# Create a PSE (Personal Security Environment) which will be used to contain the public root certificate of SAP HANA Cloud.
# Press enter twice to not provide a pin
sapgenpse gen_verify_pse -p "$SECUDIR/sapcli.pse"
Shell
# Add the certificate to the PSE
sapgenpse maintain_pk -p "$SECUDIR/sapcli.pse" -a ~/.ssl/DigiCertGlobalRootCA.crt.pem
# View the contents of the PSE
sapgenpse maintain_pk -p "$SECUDIR/sapcli.pse" -l
# Connect using the SAP commoncrypto library rather than OpenSSL. Replace the host, user, and password values.
hdbsql -sslprovider commoncrypto -n 3b2gf55e-4214-4bd9-adfc-f547d8e2d384.hana.trial-us10.hanacloud.ondemand.com:443 -u <USER> -p <Password>
Shell
mkdir ~/.ssl
# Download the public root certificate used by HANA Cloud
wget --no-check-certificate https://cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem -O ~/.ssl/DigiCertGlobalRootCA.crt.pem
# Show the command help for the sapgenpse
sapgenpse -h
# SECDIR & LD_LIBRARY_PATH environment variables are required when using the commoncrypto library
export SECUDIR=~/sap/hdbclient
export LD_LIBRARY_PATH=~/sap/hdbclient:$LD_LIBRARY_PATH
# macOS only
export DYLD_LIBRARY_PATH=~/sap/hdbclient
# Create a PSE (Personal Security Environment) which will be used to contain the public root certificate of SAP HANA Cloud.
# Press enter twice to not provide a pin
sapgenpse gen_verify_pse -p "$SECUDIR/sapcli.pse"
Shell
# Add the certificate to the PSE
sapgenpse maintain_pk -p "$SECUDIR/sapcli.pse" -a ~/.ssl/DigiCertGlobalRootCA.crt.pem
# View the contents of the PSE
sapgenpse maintain_pk -p "$SECUDIR/sapcli.pse" -l
# Connect using the SAP commoncrypto library rather than OpenSSL. Replace the host, user, and password values.
hdbsql -sslprovider commoncrypto -n 3b2gf55e-4214-4bd9-adfc-f547d8e2d384.hana.trial-us10.hanacloud.ondemand.com:443 -u <USER> -p <Password>
Shell
REM In a browser download https://cacerts.digicert.com/DigiCertGlobalRootCA.crt.pem
REM Show the command help for the sapgenpse
sapgenpse -h
REM SECDIR environment variable is required when using the commoncrypto library
set SECUDIR=C:\SAP\hdbclient
REM Create a PSE (Personal Security Environment) which will be used to contain the public root certificate of SAP HANA Cloud.
REM Press enter twice to not provide a pin
sapgenpse gen_verify_pse -p "%SECUDIR%/sapcli.pse"
REM if the above command fails, try using the -log option for additional output.
Shell
REM Add the certificate to the PSE
sapgenpse maintain_pk -p "%SECUDIR%/sapcli.pse" -a %USERPROFILE%/Downloads/DigiCertGlobalRootCA.crt.pem
REM View the contents of the PSE
sapgenpse maintain_pk -p "%SECUDIR%/sapcli.pse" -l
REM Connect using the SAP commoncrypto library rather than OpenSSL. Replace the host, user, and password values.
hdbsql -sslprovider commoncrypto -n 3b2gf55e-4214-4bd9-adfc-f547d8e2d384.hana.trial-us10.hanacloud.ondemand.com:443 -u <USER> -p <Password>
For additional details see [Server Certificate Authentication](https://help.sap.com/docs/SAP_HANA_CLIENT/f1b440ded6144a54ada97ff95dac7adf/a95754380f4c4c05b728524f9cd652e3.html).
  1. Type \s for status information

    Shell
    \s

    Notice that for the SAP HANA Cloud instance, the version number is 4.x.

    Connect to HANA Cloud
    Connect to HANA Cloud

    Notice that for the on-premise instance, the version number is 2.x.

    Connect to an on-premise SAP HANA
    Connect to an on-premise SAP HANA

Step 2 Create user and schema
+
Step 3 Store connection details in secure user store (hdbuserstore)
+
Step 4 Create tables and insert data
+
Step 5 Interactive, non-interactive, substitution variables, and prepared statements
+
Step 6 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 6
1. Connect to SAP HANA using hdbsql 2. Create user and schema 3. Store connection details in secure user store (hdbuserstore) 4. Create tables and insert data 5. Interactive, non-interactive, substitution variables, and prepared statements 6. Knowledge check
Next