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 the SQL Console

Create a user group, users, roles, and populate a sample schema that includes tables, views, functions, and stored procedures using the SQL console in SAP HANA Cloud Central.

Overview

🎓 beginner 15 min. SAP HANA CloudBeginnerSAP HANA Cloud SAP HANA DatabaseSql

You will learn

  • How to create a user group, users, roles, and a schema
  • How to create tables and rows to the tables using insert statements
  • How to create views, functions, and stored procedures
  • How to schedule stored procedures so they can be executed at a specified time
MICHELLE WANG M MICHELLE WANG August 13, 2026
Created by August 12, 2026
Contributors

Prerequisites

Prerequisites

Steps

Intro

The following steps create a sample hotel dataset using CREATE and INSERT statements. Additional tutorials in this group cover how to access tables in other databases using remote sources and how to perform import and export operations that are better suited for moving data into or out of a database. The next tutorial demonstrates how to explore the created objects using the Database Objects app.


Step 1 Create a usergroup, users, roles, and a schema

  1. In SAP HANA Cloud Central, open a SQL console connected to your SAP HANA database instance.

    Open SQL Console
    Open SQL Console

    The connected user is DBADMIN. In this step, you will create USER1 and USER2, which are used throughout the rest of this tutorial group.

  2. Execute the following 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;
    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, as a better practice, assigned to a role that has a defined set of privileges.

    It is recommended not to use the DBADMIN user for day-to-day operations in production environments. For additional details see Deactivate the DBADMIN User.

    For additional details on the commands above, consult CREATE USERGROUP Statement, CREATE USER Statement, CREATE ROLE Statement, and GRANT Statement.

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

    User & Role Management in HCC
    User & Role Management in HCC

  3. Open a new SQL console tab by pressing the + in the tab bar. This time we wish to connect with USER1 and to set the schema to HOTELS so we will not use the cached credentials (DBADMIN).

    Click on Select an Instnace and choose the SAP HANA database.

    Choose Connect …

    Connect New User
    Connect New User

    Specify USER1 and Password1.

    Click on Current Schema in the tab bar and choose HOTELS.

    Change Schema
    Change Schema

    Alternatively, the last two actions could have performed the below SQL.

    SQL
    CONNECT USER1 PASSWORD Password1;
    SET SCHEMA HOTELS;

    The details of the connection also be found in the connection details dialog.

    connection details
    connection details

  4. The following example demonstrates the privilege assignments that were previously created. USER1 was granted the HOTEL_ADMIN role which has all privileges the HOTELS schema while USER2 was granted the HOTEL_READER role which has only select privileges on the HOTELS schema. Execute the below SQL and notice that USER2 does not have the privilege to perform an insert. Press Skip on the SQL Execution Error dialog so that execution continues and the TEST table is removed.

    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, 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 (optional)
+
Step 4 Create a partition
+
Step 5 Create views
+
Step 6 Create functions and stored procedures
+
Step 7 Examine the created objects using 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 (optional) 4. Create a partition 5. Create views 6. Create functions and stored procedures 7. Examine the created objects using monitoring views 8. Schedule a stored procedure 9. Knowledge check

Learn more →