Databases Reference
In-Depth Information
To open an SQL editor window in the HANA Studio, we click on the system name in the
Navigator
pane, then click on the
SQL
button, which is at the top of the
Navigator
pane.
A text editor will open in the middle of the screen, alongside the
Quick Launch
pane.
If you are not currently connected to a SAP HANA system, then the
SQL editor window will open, but with no connection established
to the database. If this should happen to you, just close and reopen
the Studio and try again.
The following code creates a
topic
schema in the database, and inside that schema creates our
two example tables,
CUSTOMERS
and
ORDERS
. Some simple example data is inserted into both
the tables. We'll be using this sample data throughout the topic to show the various features of
SAP HANA:
create schema "BOOK";
grant select on schema "BOOK" to _SYS_REPO with grant option;
This instruction creates a schema, which is just a logical grouping of tables. If your SAP HANA
system already contains a schema called
topic
, then this statement will fail. If this happens, just
rename the schema to something else, maybe
HANABOOK
.
The second instruction,
grant
, is necessary to create views. Since we created the
topic
schema manually, the SAP HANA metadata doesn't know about it, so we have to do this bit of
housekeeping ourselves. In this way, the background process of the SAP HANA studio will be
able to correctly read the tables in our schema. If we don't execute this
grant
instruction, we
won't be able to create views later, because the Studio won't have access to our tables.
CREATE COLUMN TABLE "BOOK"."CUSTOMERS"
(
"CUST_ID" INTEGER CS_INT NOT NULL ,
"CUST_NAME" VARCHAR(25) NOT NULL ,
"CUST_COUNTRY" VARCHAR(20)
);
The previous SQL statement creates a simple table. Note that we're creating a
COLUMN
table
(using the column-based storage). Of course, we could create a row-based table using
CREATE
TABLE CUSTOMERS
, but that would defeat the purpose of using SAP HANA really. If you
changed the name of the schema from
topic
to something else, then you'll need to change it
here too.
Now, we'll put some sample data into our
CUSTOMERS
table, using the following SQL statements:
insert into "BOOK"."CUSTOMERS" values(1,'Smith','GB');
insert into "BOOK"."CUSTOMERS" values(2,'Jones','GB');
insert into "BOOK"."CUSTOMERS" values(3,'Martin','FR');
insert into "BOOK"."CUSTOMERS" values(4,'Machin','FR');