You are on page 1of 2

Introduction of SQLScript:

--------------------------

The SAP HANA database has its own scripting language named SQLScript.

SQLScript is a collection of extensions to StructuredQueryLanguage (SQL).

SYNTAX FOR CREATION OF SCHEMA :


-------------------------------

CREATE SCHEMA <SCHEMA_NAME>;

GRANT ACCESS TO SCHEMA :


------------------------

GRANT SELECT ON SCHEMA "SCHEMA NAME" TO "_SYS_REPO" WITH GRANT OPTION ;

CREATE TABLE IN SAP HANA:


-------------------------
Example:

Syntax:
CREATE TABLE "PRACT"."JAYANT"
(
"EMPID" INTEGER NOT NULL PRIMARY KEY ,
"EMPNM" VARCHAR(20)
);

insert into "PRACT"."JAYANT" values (101,'ABC');


insert into "PRACT"."JAYANT" values (102,'DEF');
insert into "PRACT"."JAYANT" values (103,'GHI');

IMP POINT :By default it will create Row store Table .For coloumn table we have to
define "COLUMN".

Syntax for column Table :

CREATE COLUMN TABLE "PRACT"."JAYANT1"


(
"EMPID" INTEGER NOT NULL PRIMARY KEY ,
"EMPNM" VARCHAR(20)
);

insert into "PRACT"."JAYANT" values (101,'ABCD');

DROP TABLE STATEMENT( Removes Table from Data Base )


----------------------------------------------------
Syntax: DROP TABLE <Schema name>.<Table name>;

Example: DROP TABLE "PRACT"."PARTNER";

DELETE STATEMENT :(Removes record from Table)


---------------------------------------------

Syntax : DELETE [HISTORY] FROM <table_name> [WHERE <condition>]

NB:The DELETE statement deletes records from a table where the <condition> is met.
If the WHERE clause is omitted, then DELETE removes all records from a table.
SELECTING DATA :( SELECT CLAUSE & FROM CLAUSE )
----------------

Syntax:
Select * from <table_name>; -- here * indicates all columns
or
Select col1, col2, coln from <table_name>;

Example :

SELECT "region_code","region_name","SUB_REGION_NAME"
from "PRACT"."PRO_REGION";

SELECTING DATA FROM TWO TABLE :


-------------------------------
Example :

SELECT
A."region_code",A."region_name",A."SUB_REGION_NAME",
B."product_id",B."sales_amount"
from
"PRACT"."PRO_REGION" AS A
JOIN
"PRACT"."PRO_SALES" AS B
ON
A."region_code" = B."region_code";

GROUPBY AND HAVING CLAUSE :


---------------------------
SELECT
A."region_code" ,A."product_id",
SUM(A."sales_amount")AS "sales_amount"
from
"PRACT"."PRO_SALES" as A
GROUP BY A."region_code",A."product_id"
having A."region_code" = '100';