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

Change Data Structures Using HDBTABLE and HDBMIGRATIONTABLE Objects

Change data structures by adding columns to a table using HDBTABLE and HDBMIGRATIONTABLE objects.

Overview

🎓 beginner 10 min. SAP HANA CloudBeginnerSAP HANA CloudSAP HANA DatabaseSAP Business Application Studio

You will learn

  • โœ”How to change table definition in an HDBTABLE object
  • โœ”How to recreate the table using an HDBMIGRATIONTABLE object
  • โœ”How to change table definition in an HDBMIGRATIONTABLE object
  • โœ”How to insert migration definition in an HDBMIGRATIONTABLE object Are you wondering what the best way is to manage changing data structures? Do you want to know how to collaborate more efficiently when working in development projects?
Unknown U Unknown July 18, 2024
Created by October 19, 2021
Contributors

Prerequisites

Prerequisites

Steps

Intro

To answer the first question, learn what benefits different table types in SAP HANA Cloud, SAP HANA database can offer you based on your needs. The following 3 tutorials in this tutorial group will help you navigate through your challenges with the managing data structures:

  1. Get started to collaborate in SAP Business Application Studio

  2. Import data into a table in SAP HANA Database Project

  3. You are here โ˜› Change data structures using HDBTABLE and HDBMIGRATIONTABLE objects

    To answer the second question, create template projects that help you set up service connections, handle synonyms and prepare authorization management. You can create these templates once in the beginning and give your project team members a head-start. Using the template, they can build on your work and can quickly start working productively.

    The following 4 tutorials in this tutorial group will help you learn how to collaborate efficiently:

  4. Prepare your SAP HANA Database Project for collaboration

  5. Generate users and roles for assigning privileges

  6. Enhance your project with services, synonyms, and grants

  7. Collaborate on an SAP HANA Database Project template

This tutorial will show you how to change data structures using HDBTABLE and HDBMIGRATIONTABLE objects.

Step 1 Change data structures using `HDBTABLE` and `HDBMIGRATIONTABLE` objects
โ€”

Now that your table is created and the data is imported, we will change the structure of this table by adding two columns. You can then examine in the terminal how this type of object handles data structure changes, which we will compare to other table types later.

  1. Go back to SAP Business Application Studio and select your inventory.hdbtable.

  2. Add two columns to the table definition by copying the following code and pasting at the end of the line 30.

    SQL

“ADDITIONALATTRIBUTESTRING” NVARCHAR(10), “ADDITIONALATTRIBUTESTRINGNN” NVARCHAR(10) NOT NULL DEFAULT ‘TEST’

Code

    Make sure to paste these lines in between the last column definitions and the closing parenthesis `')'` in **line 31**. The last previous line of column definitions needs to have a ',' at the end.

    The new table definition should look like this image:

    ![Add columns HDBTABLE](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-collaborative-database-development-3/ss_01_add_columns_HDBTABLE.png)

3.	Now you can deploy this updated object again to your database by clicking on the ![Deploy](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-collaborative-database-development-3/icon-deploy.png) deploy icon in the SAP HANA Projects panel. You can either deploy only the file `inventory.hdbtable` or the whole project.




### Verify the changes to the data structure using Database Explorer


1.	Once the table was successfully deployed, you can check if the data is still in the table by going back to the SAP HANA Database Explorer and refreshing the table.

2.	In the table definitions, you should now see that two additional columns have been added to the table and opening the data should not result in any changes to the number of rows in the previous graph.

![Updated Inventory table](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-collaborative-database-development-3/ss_02_updated_inventory_table.png)

You may also check the data in the table to verify that it contains the same data as it had earlier. You can do this by comparing the output graph of [Step 5 from the previous tutorial](hana-cloud-collaborative-database-development-2) to what you get with the current table.

> ### **Important**
> While making changes to data structure using `HDBTABLE`, your database recreates the existing table with the updated table definition and copies the existing data into it. This is not the most efficient way to use your database capability if you have large amounts of data present in these tables.


> To highlight how to make changes to data structures efficiently, you will use an `HDBMIGRATIONTABLE` in the next section. In comparison to using an `HDBTABLE`, an `HDBMIGRATIONTABLE` can save considerable time and resources while handling changes in data structures.





### Recreate the table using an HDBMIGRATIONTABLE object


Now that you know how `HDBTABLE` objects handle data changes, you can use a different type of object to add two more rows to this table.

1.	Go back to SAP Business Application Studio. Right-click your `inventory.hdbtable` and select Duplicate.

    ![Duplicate HDBtable](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-collaborative-database-development-3/ss_03_duplicate_HDBtable.png)


2.	Now, you can see a new file named `inventory_copy.hdbtable` in your `src` folder. Right-click on this file and select Rename. Rename the file as `'inventory.hdbmigrationtable'`.

    >**Important:**
> Before you deploy the new file `inventory.hdbmigrationtable`, you must make a change to the already existing `inventory.hdbtable` file. Otherwise, the deployment will result in an error. Adding the ending `'.txt' ` to the file name will signal to SAP Business Application Studio, that this file shall not be deployed to create an HDI object in the database.

3.	Rename the `inventory.hdbtable` as `inventory.hdbtable.txt` to facilitate the deployment of `inventory.hdbmigrationtable`.

4.	Now, click on the `inventory.hdbmigrationtable` file. Copy and paste the following code at the beginning of the file such that it comes before the table definition.

    ```SQL
== version = 1
![Adding version 1](https://raw.githubusercontent.com/sap-tutorials/Tutorials/master/tutorials/hana-cloud-collaborative-database-development-3/ss_04_adding_version_1.png)
  1. On the bottom left corner, you can see the file inventory.hdbmigrationtable in the SAP HANA Projects panel. Click on the deploy icon for the file to deploy the changes to your HDI container.

  2. In the terminal you can see that the table was successfully deployed.

  3. Go back to the SAP HANA Database Explorer, right-click on Tables and select Refresh to update the changes you made to the table.

  4. Click on the INVENTORY table to view the list of all the columns present. Here, you can verify that deploying the inventory.hdbmigrationtable has produced exactly the same results as with inventory.hdbtable.

Step 2 Change table definition in HDBMIGRATIONTABLE object
+
Step 3 Insert migration definition in HDBMIGRATIONTABLE object
+
Step 4 Test yourself
+

Resources

Discussion

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

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Change data structures using `HDBTABLE` and `HDBMIGRATIONTABLE` objects 2. Change table definition in HDBMIGRATIONTABLE object 3. Insert migration definition in HDBMIGRATIONTABLE object 4. Test yourself

Learn more →