SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Create Database Objects with SAP HANA Database Explorer

Create a user group, users, roles, and populate a sample schema that includes tables, views, functions and procedures using the SQL console.

Overview

🎓 beginner 10 min. SAP HANA CloudBeginnerSAP HANA Cloud SAP HANA DatabaseSAP HANASAP HANA Express EditionSql

You will learn

  • โœ”How to create a user group, users, roles, and a schema
  • โœ”How to create tables and import data using insert statements
  • โœ”How to create views, functions, and stored procedures
Unknown U Unknown May 11, 2026
Created by March 29, 2022
Contributors

Prerequisites

Prerequisites

  • An SAP HANA database such as SAP HANA Cloud free tier, or the SAP HANA, express edition that includes the SAP HANA database explorer

Steps

Intro

The following steps will create a sample hotel dataset using create and insert statements. The next tutorial will demonstrate some of the ways these objects can be exported or imported.


Step 1 Create a usergroup, users, roles, and a schema
โ€”

  1. In the SAP HANA database explorer, select the database HC_HDB and open a SQL console.

    Open SQL console
    Open SQL console

    Notice that the user in the SQL console is DBADMIN if using SAP HANA Cloud, or SYSTEM if using an on-premise SAP HANA database. In this step we will create a new user, USER1 that will be used throughout the rest of the tutorials in this tutorial group.

  2. Execute the below SQL.

    SQL
    CREATE USERGROUP HOTEL_USER_GROUP SET PARAMETER 'minimal_password_length' = '8', 'force_first_password_change' = 'FALSE';
    CREATE USER USER1 PASSWORD Password1 no force_first_password_change SET USERGROUP HOTEL_USER_GROUP;
    CREATE USER USER2 PASSWORD Password2 no force_first_password_change SET USERGROUP HOTEL_USER_GROUP;
    --SELECT * from "PUBLIC"."M_EFFECTIVE_PASSWORD_POLICY" where USER_NAME = 'USER1';
    --SELECT * FROM USERS;
    
    GRANT CREATE SCHEMA TO USER1;
    --GRANT ROLE ADMIN TO USER1;
    CREATE ROLE HOTEL_ADMIN;
    CREATE ROLE HOTEL_READER;
    
    GRANT TRUST ADMIN TO HOTEL_ADMIN; -- required to create a PSE
    GRANT CERTIFICATE ADMIN TO HOTEL_ADMIN; --required to create a certificate
    GRANT CREDENTIAL ADMIN TO HOTEL_ADMIN; --required to create a credential
    GRANT EXPORT TO HOTEL_ADMIN; --required to enable export of data
    GRANT IMPORT TO HOTEL_ADMIN; --required to enable import of data
    GRANT CREATE REMOTE SOURCE TO HOTEL_ADMIN; --allow setting the PSE purpose to REMOTE SOURCE and to create REMOTE SOURCES
    GRANT RESOURCE ADMIN TO HOTEL_ADMIN; --allow viewing of diagnostic files
    GRANT CATALOG READ TO HOTEL_ADMIN;   --allow access to system views
    GRANT INIFILE ADMIN TO HOTEL_ADMIN;  --allow altering of system settings
    
    GRANT HOTEL_ADMIN TO USER1;
    GRANT HOTEL_READER TO USER2;
    
    CONNECT USER1 PASSWORD Password1;
    CREATE SCHEMA HOTELS;
    GRANT ALL PRIVILEGES ON SCHEMA HOTELS TO HOTEL_ADMIN;
    GRANT SELECT ON SCHEMA HOTELS TO HOTEL_READER;
    
    --view the objects owned by USER1
    SELECT SCHEMA_NAME, OBJECT_NAME, OBJECT_TYPE, OWNER_NAME FROM "PUBLIC"."OWNERSHIP" WHERE OWNER_NAME = 'USER1';

    A schema provides a way to group database objects together.

    Privileges can be assigned to users directly or a better practice is to assign users to a role that has a set of privileges.

    It is recommended to not use the DBADMIN user for day-to-day operations in production environments. Having specific users for specific tasks also will aid in auditing. For additional details see Deactivate the DBADMIN User.

    For additional details on the commands above consult CREATE USERGROUP Statement, CREATE USER Statement (Access Control), CREATE Role Statement, and GRANT Statement. The user USER1 will be used in the remainder of this tutorial group.

    Users and roles can also be managed in the SAP HANA Cloud Cockpit under the User & Role Management tile. Additional details can be found at User and Role Management.

    roles management
    roles management

  3. Add another SAP HANA database connection using USER1.

    Select the Add instance icon and provide the details to connect to your SAP HANA database. Provide the user name of USER1 and password of Password1 as well as set the schema to be HOTELS in the advanced options.

    add new user1 connection
    add new user1 connection

    Open a new SQL console and notice that it using USER1 and the schema is HOTELS.

    user1 connection sql console
    user1 connection sql console

  4. The following example demonstrates the privileges using the newly opened SQL console. Notice that USER2 does not have the privilege to perform an insert.

    SQL
    CREATE TABLE TEST(
      myValue NVARCHAR(50)
    );
    
    --USER1 has all privileges on the HOTELS schema
    SELECT * FROM TEST; --succeeds
    INSERT INTO TEST VALUES('Value1'); --succeeds
    
    --USER2 can only select
    CONNECT USER2 PASSWORD Password2;
    SET SCHEMA HOTELS;
    SELECT * FROM TEST; --succeeds
    INSERT INTO TEST VALUES('Value2'); --fails
    
    --Remove the unused table
    CONNECT USER1 PASSWORD Password1;
    SET SCHEMA HOTELS;
    DROP TABLE TEST;
  5. The following statements can be used to delete the schema and objects it contains as well as the users, user group and roles once the tutorials are complete.

    Do not execute the below until the tutorials are complete.

    SQL
    -- DO NOT EXECUTE THIS UNLESS YOU WISH TO CLEAN UP THE TUTORIAL OBJECTS
    CONNECT DBADMIN PASSWORD myPassword;
    DROP USER USER1 CASCADE;
    DROP USER USER2 CASCADE;
    DROP USERGROUP HOTEL_USER_GROUP;
    DROP ROLE HOTEL_ADMIN;
    DROP ROLE HOTEL_READER;
Step 2 Create and populate tables
+
Step 3 Explore auto-commit
+
Step 4 Create a partition
+
Step 5 Create views
+
Step 6 Create functions and stored procedures
+
Step 7 Examine the created objects using the monitoring views
+
Step 8 Schedule a stored procedure
+
Step 9 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 9
1. Create a usergroup, users, roles, and a schema 2. Create and populate tables 3. Explore auto-commit 4. Create a partition 5. Create views 6. Create functions and stored procedures 7. Examine the created objects using the monitoring views 8. Schedule a stored procedure 9. Knowledge check

Learn more →