-1

Pretty much as the title states: What is the difference between CREATE TABLE and CREATE COLUMN TABLE?

Both seemingly create a table, so what is the difference?

4
  • I´m pretty sure that you are wrong with your assumption. CREATE TABLE is a very SQL style to create a table. As far as I could google within minutes, there is no "COLUMN TABLE" statement. But - you can prove me wrong. May 6, 2020 at 14:11
  • CREATE TABLE can also be used in SAP HANA: help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/… but there is also the COLUMN TABLE in Hana which creates a Table
    – user12727262
    May 6, 2020 at 14:39
  • I am no expert but do you mean CREATE COLUMN TABLE? At least that's what documented in the link you provided. CREATE TABLE can mean both row based and column based, depends on whether the table is temp or non-temp. CREATE <table_type> TABLE gives you the option to manually choose COLUMN (or ROW).
    – Marc
    May 6, 2020 at 15:10
  • As I mentioned, there is no "COLUMN TABLE" statement, but a table type "COLUMN". The of Lars B. is very clear. And you should mark it as the valid answer! May 7, 2020 at 7:29

1 Answer 1

5

SAP HANA supports tables that store data in a column store or a row store.

These refer to different ways of how the database (HANA) manages the data stored in the tables.
They do not affect how the data can be used in a SQL statement whatsoever.

Technically, the syntax for CREATE TABLE in HANA has been extended to include a way to choose which of the two table types should be created:

CREATE [COLUMN|ROW] TABLE <table_name> ...

This means one can (and probably should) include the table type desired in any CREATE TABLE command, but can also choose to not do that (i.e. to keep compatibility which standard SQL).

The default setting

Now, which table type you get when not specifying the table type depends on a HANA parameter in the indexserver.ini configuration file. If the parameter [sql] - [default_table_type] is set to row then not specifying the table type will get a table stored in the row store. This is also the default value for the parameter up until HANA 2 SPS 03 if I'm not mistaken.

With HANA 2 SPS 04 the default for the parameter was finally changed to column.

What you should use

This is important: with SAP HANA you want the table type to be COLUMN in nearly all cases.

Row store tables have very different performance and memory requirement characteristics and really only serve very specific data access and modification patterns. Those patterns are for example:

  • always full row access by selecting the complete primary key.
  • high frequency of UPDATEs on records (think updating the same record thousands of times a second).
  • records with nearly distinct records in every/most column/s that absolutely need to be in memory at all times.

For the vast majority of all use cases and data types CREATE COLUMN TABLE is the right choice in SAP HANA. Column store tables support compression, partitioning, memory displacement, and many other techniques that are not available for row store tables.

The difference it makes to your programs

And yet, both table types "look and feel" the same to any SQL command. To give an analogy, other DBMS support different table types like "cluster" or "heap" that affect how data gets stored internally while the tables can be used regardless of the chosen type.
The HANA setting for column or row store is a similar choice about internal storage.

All that (and a lot more) is of course documented (e.g. here) and explained in many different places (e.g. my book SAP HANA Administration).

What column and row store is not about

Note that the choice between column or row store has nothing to do with whether the table is a temporary or permanent table. Both table types permanently persist the data as one would expect.

Of course, one can always use CREATE TEMPORARY TABLE which also comes with a whole range of option... CREATE TEMPORARY { ROW | COLUMN } TABLE | LOCAL TEMPORARY { ROW | COLUMN } TABLE but for this answer let's pretend we didn't see that to save our sanity.

Take away

It's quite important to understand that HANA has those two fundamentally different implementations of in-memory tables.
Make sure you don't accidentally (by using the default) create row store tables for your mass data analytics or really for most use cases.
Whenever you're unsure about the table type, start off with a column store table and see if that works for your use case. Should you actually have a use case for which row store is the better option, you can (nearly) always convert a table from one storage type to the other via an ALTER TABLE command.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.