Documente Academic
Documente Profesional
Documente Cultură
This statement is used to either change the parameters of a fulltext index or the
state of an index processing queue.
The queue is a mechanism used to enable a fulltext index to operate in
asynchronous manner, i.e. inserts will not block until a document is processed.
Parameters:
We can use the below parameters while altering the full text index in SAP HANA.
Specifies the phrase index ratio. The value used must be between 0.0 and 1.0
QUEUE COMMAND:
Specifies an action to be performed on the index queue. We can use three types
of commands.
FLUSH: Updates the fulltext index with the documents in the queue that have
already been processed.
SUSPEND: Suspends the fulltext index processing queue.
ACTIVATE: Activates the fulltext index processing queue.
Example:
ALTER INDEX
ALTER INDEX:
This statement is used to rebuild the index for existing index in SAP HANA
database.
Syntax: ALTER INDEX <schema_name>.<table_name> REBUILD
Example:
ALTER SEQUENCE
ALTER SEQUENCE:
Parameters:
We can use different parameters while altering sequence in SAP HANA. They are
START WITH:
INCREMENT BY:
The amount the next sequence value is incremented from the last value assigned.
The default is 1.
You specify a negative value to generate a descending sequence.
An error is returned if the INCREMENT BY value is 0.
MAXVALUE:
NO MAXVALUE:
When the NO MAXVALUE directive is used the maximum value for an ascending
sequence will be 4611686018427387903 and the maximum value for a
descending sequence will be -1.
MINVALUE:
The minimum value that a sequence can generate. <min_value> must be
between -4611686018427387904 and 4611686018427387902.
NO MINVALUE:
When the NO MINVALUE directive is used, the minimum value for an ascending
sequence is 1 and the minimum value for a descending sequence is -
4611686018427387903.
CYCLE:
When the CYCLE directive is used the sequence number will be restarted after it
reaches its maximum or minimum value.
NO CYCLE:
Default option.
When the NO CYCLE directive is used the sequence number will not be restarted
after it reaches its maximum or minimum value.
CACHE:
The cache size with which a range of sequence numbers will be cached in a node.
<cache_size> must be unsigned integer.
An error is returned if the CACHE is less than 2 or greater than min(MAXVALUE –
MINVALUE, 30000). 2 <= <cache_size> <= min(MAXVALUE – MINVALUE,
30000)
NO CACHE:
Default option.
When the NO CACHE directive is used, the sequence number will not be cached in
a node.
RESET BY:
If RESET BY is not specified, the sequence value is stored persistently in database. During the
restart of the database, the next value of the sequence is generated from the saved sequence
value.
Examples:
1. Alter sequence SCHEMA_NAME.SEQUENCE_ORD_NUM to add 10000 as maximum
value and no minimum value.
ALTER TABLE
ALTER TABLE:
This statement is used to change the table definition which has been set using
CREATE TABLE statement.
We can do lot of modifications to the existing table using ALTER statement. Let see the
examples for most common things we on everyday basis.
Examples:
Note: UNLOAD PRIORITY can be anything between 0 and 9 where 0 means not
unloadable and 9 means earliest unload.
16. Alter table to change the location from hana in-memory to extended storage.
17. Alter table to change the location from extended storage to hana in-memory
23. Alter table to drop the replicas in all index server locations.
24. Alter table to move replica from one index server to another.
Note: We can run also run one time delta using the below statement.
This statement is used to define or undefine virtual table and column properties.
Any properties that are not set using ALTER VIRTUAL TABLE statement are
marked as read-only, which cannot be updated by the ALTER VIRTUAL TABLE
statement.
Syntax:
Example:
1. Alter virtual table SCHEMA_NAME.VT_ORDERS_DATA to set the property name1
to value 1.
COMMENT ON
COMMENT ON:
Syntax:
Examples:
Useful Tip:
Once the comments are added, we can check them using the below views in SYS
schema in SAP HANA database.
TABLES – Hold information about table comments in SAP HANA.
TABLE_COLUMNS – Holds information about table column comments.
VIEWS – Holds information about views comments.
VIEW_COLUMNS – Holds information about view column comments.
This statement is used create an explicit full text index on the given table column.
This is mostly used when we want to text analysis.
Full text index is supported for the following data types:
o VARCHAR, NVARCHAR types with CS_STRING type
o VARBINARY type
o BLOB, CLOB, NCLOB types
Different Parameters that can be used to create Full text Index are:
LANGUAGE COLUMN:
PHRASE INDEX RATIO: Specifies the percentage of the phrase index. Value must be
between 0.0 and 1.0
CONFIGURATION:
Defines if the original document should be stored or only the search results.
When set to ON the original document content is not stored.
If set to ON, fast preprocessing is used, i.e. linguistic searches are not possible.
MIME TYPE:
TOKEN SEPARATORS:
A set of characters used for token separation. Only ASCII characters are
considered.
SYNC[HRONOUS]:
ASYNC[HRONOUS]:
Enables text mining capabilities on the indexed column. Text mining provides
functionality that can compare documents by examining the terms used within
them.
The path to a custom configuration file for text mining. If not specified,
DEFAULT.textminingconfig is used.
Example:
CREATE INDEX
CREATE INDEX:
This statement is used to create index on a table with specified columns in SAP
HANA system.
Things to Remember:
1. When columns data types are character string types, binary string types, decimal
types or when the table constraint is composite key, or non-unique constraint,
the default index type is CPBTREE.
2. In other cases BTREE will be created. In neither BTREE nor CPBTREE keyword is
specified, then SAP HANA database creates appropriate index type.
UNIQUE:
SAP HANA creates unique index on the specified table and column.
While creating index system performs duplicate check as well as when new record
added to the table.
The columns used in the UNIQUE index should not contain duplicate values.
BTREE:
SAP HANA creates BTREE index on the specified table and columns.
B+ tree uses an index tree that maintains sorted data in way that performs
efficient insertion, deletion and search of records in table.
CPBTREE:
Column Order:
Global Order:
Fillfactor:
Examples:
1. Create BTREE index on table ORDERS_DATA for column ORDER_NUMBER with
descending order.
Useful Tip:
We can check list of indexes created in the system and their names along with
dependent tables and columns using the below views under SYS schema.
INDEXES – Holds information about currently defined indexes on tables
INDEX_COLUMNS – Holds index columns information.
CREATE SCHEMA
CREATE SCHEMA:
Examples:
Useful Tip:
We can check the owner information for all the schemas in the system using
below view in SYS schema.
SCHEMAS – Holds information about schemas and its owners in the system.
CREATE SEQUENCE
CREATE SEQUENCE:
Parameters:
We can use different parameters while creating sequence in SAP HANA. They are
START WITH:
INCREMENT BY:
The amount the next sequence value is incremented from the last value assigned.
The default is 1.
You specify a negative value to generate a descending sequence. An error is
returned if the INCREMENT BY value is 0.
MAXVALUE:
NO MAXVALUE:
When the NO MAXVALUE directive is used the maximum value for an ascending
sequence will be 4611686018427387903 and the maximum value for a
descending sequence will be -1.
MINVALUE:
NO MINVALUE:
When the NO MINVALUE directive is used, the minimum value for an ascending
sequence is 1 and the minimum value for a descending sequence is -
4611686018427387903.
CYCLE:
When the CYCLE directive is used the sequence number will be restarted after it
reaches its maximum or minimum value.
NO CYCLE:
Default option. When the NO CYCLE directive is used the sequence number will
not be restarted after it reaches its maximum or minimum value.
CACHE:
The cache size with which a range of sequence numbers will be cached in a node.
<cache_size> must be unsigned integer.
An error is returned if the CACHE is less than 2 or greater than min(MAXVALUE –
MINVALUE, 30000). 2 <= <cache_size> <= min(MAXVALUE – MINVALUE,
30000)
NO CACHE:
Default option. When the NO CACHE directive is used, the sequence number will
not be cached in a node.
RESET BY:
Examples:
4. Use the next value of sequence while inserting data into table.
CREATE STATISTICS
CREATE STATISTICS:
This statement is used to create data statistics objects which approximate the
specified <data_sources>.
Data statistics objects are used to estimate the properties of the data without
directly accessing the data itself.
This can be useful during query optimization, query execution, etc.
Properties:
Data statistics properties specifies the properties of the data statistics objects to
be built from the specified data sources.
Different Properties that we can choose are,
TYPE: In general, any data statistics type can be built for any data source,
however some data statistics types may not be appropriate for a given data
source.
o For example, highly volatile data sources, like a delta store, should have
data statistics which can be efficiently updated when data updates occur.
o A data source can have only one data statistics object of a certain type:
one of type HISTOGRAM, and one data statistics object of the type
SIMPLE.
o RECORD COUNT specifies that only the number of records is computed.
o The RECORD COUNT type is available for virtual tables only.
o The RECORD COUNT statistics can only be created on tables (not on
columns). If TYPE is not specified, both simple and histogram statistics will
be created.
o The type can be HISTOGRAM, SIMPLE, ALL, RECORD COUNT.
o The default type is ALL
HISTOGRAM: The HISTOGRAM type specifies a one-dimensional data statistics
object.
SIMPLE: SIMPLE specifies basic statistics, such as min, max, null count, count,
distinct count.
CONSTRAINT:
Default:
MAXDIFF for virtual tables and QOPTIMAL for other data sources.
BUCKETS:
Default:
QERROR:
Default:
QTHETA:
Default:
MEMORY PERCENT:
A data statistics object can use large amount of memory for some data sources.
The MEMORY parameter can used to limit the amount of memory used for data
statistics objects.
<memory_percentage> is specified as percentage of the space used by the data
source itself.
It represents the maximum amount of memory which can be used for the data
statistics object.
For example, if a data source is a table column which uses 100 MB of memory,
and <memory_percentage> is 5.
The data statistics object for this column can use, at most, 5 MB for its memory
representation.
Default:
MEMORY:
PERSISTENT (on/off):
PERSISTENT can be specified only for CREATE and ALTER STATISTICS statements
when TYPE is HISTOGRAM.
It specifies if the histogram data will be persistent in a system table. The simple
statistics are always persistent.
Default: ON
Examples:
CREATE SYNONYM
CREATE SYNONYM:
This statement is used to create alternate name to actual object in SAP HANA
database.
The synonym can be created for table, view, procedure, sequence.
Syntax: CREATE [PUBLIC] SYNONYM <schema_name>.<synonym_name> FOR
<object_name>
Note:
We can create PUBLIC synonyms using PUBLIC keyword while creating synonym.
PUBLIC synonym can be accessed by all users in the system.
Example:
CREATE TABLE
CREATE TABLE:
COLUMN
ROW
HISTORY COLUMN
GLOBAL TEMPORARY
GLOBAL TEMPORARY COLUMN
LOCAL TEMPORARY
LOCAL TEMPORARY COLUMN
ROW, COLUMN:
This will make the default table type as ‘COLUMN’ instead of ROW.
HISTORY COLUMN:
GLOBAL TEMPORARY:
Table definition is globally available while data is visible only to the current
session. The table is truncated at the end of the session.
Metadata in a global temporary table is persistent meaning the metadata exists
until the table is dropped and the metadata is shared across sessions.
Data in a global temporary table is session-specific meaning only the owner
session of the global temporary table is allowed to insert/read/truncate the data,
exists for the duration of the session and data from the global temporary table is
automatically dropped when the session is terminated.
Global temporary table can be dropped only when the table does not have any
record in it.
Table definition is globally available while data is visible only to the current
session. The table is truncated at the end of the session.
Metadata in a global temporary column table is persistent meaning the metadata
exists until the table is dropped and the metadata is shared across sessions.
Data in a global temporary column table is session-specific meaning only the
owner session of the global temporary column table is allowed to
insert/read/truncate the data, exists for the duration of the session and data from
the global temporary column table is automatically dropped when the session is
terminated.
Global temporary column table can be dropped only when the table does not have
any record in it.
LOCAL TEMPORARY:
The table definition and data is visible only to the current session. The table is
truncated at the end of the session.
Metadata exists for the duration of the session and is session-specific meaning
only the owner session of the local temporary table is allowed to see.
Data in a local temporary table is session-specific meaning only the owner session
of the local temporary table is allowed to insert/read/truncate the data, exists for
the duration of the session and data from the local temporary table is
automatically dropped when the session is terminated.
The table definition and data is visible only to the current session. The table is
truncated at the end of the session.
Metadata exists for the duration of the session and is session-specific meaning
only the owner session of the local temporary column table is allowed to see.
Data in a local temporary column table is session-specific meaning only the owner
session of the local temporary column table is allowed to insert/read/truncate the
data, exists for the duration of the session and data from the local temporary
column table is automatically dropped when the session is terminated.
VIRTUAL:
Examples:
Ans:
8. Create a column table with foreign key relationship with other table.
Ans:
We can use either ON UPDATE or ON DELETE as action items for foreign key relation. Along
with action item we can use 4 types operations, they are.
MSSQL is source name, SCHEMA_NAME is Database scheam in MSSQL server and dbo is
owner of the table ORDERS_DATA.
Before we create virtual tables in HANA, we need to have remote source configured.
11. Create a table in extended storage.
13. Create a column table with dynamic columns using GENERATED ALWAYS
IDENTITY is similar to sequence that can be used for populating unique number to use it as
primary key.
Select
Statement: SELECT ORDER_NUMBER,CUST_NO,QUANTITY FROM SCHEMA_NAME.ORD
ERS_DATA
Tables with schema flexibility has flexibility to add additional columns dynamically if we insert
data for more columns than what we have in table structure. By default the columns will be
added with data type NVARCHAR(5000).
CREATE TRIGGER
CREATE TRIGGER:
This statement is used to triggers which is a set of statements that are executed
when a given operation (INSERT/UPDATE/DELETE) takes place on a given subject
table or subject view.
A trigger is special kind of stored procedure that automatically executes when an
event occurs on a given table or view.
Only database users having the TRIGGER privilege for the given
<subject_table_name> are allowed to create a trigger for that table or view.
Statement level triggers are only supported in row-store tables. You also cannot
convert row table with statement trigger into column table by using ALTER
TABLE.
Modification (any INSERT/UPDATE/DELETE/REPLACE) of a subject table that
trigger is defined on, is not allowed in the trigger body.
The trigger on a partitioned table cannot access the subject table, while a trigger
on a non-partitioned table can execute the SELECT statement on its subject table.
When a subject table is accessed in a trigger body, it does not always show row-
wise result in case of batch updates due to performance reasons.
The maximum trigger number per single table and per DML is 1024, which means
a table can have maximum 1024 INSERT triggers, 1024 UPDATE triggers and
1024 DELETE triggers in the same time.
In case of multible triggers, trigger execution order is not guaranteed. If you
need to ensure a certain set of trigger execution order, it is recommended to use
a single unified trigger instead of multiple triggers.
Procedure all inside trigger action body is supported. The procedure which is
called in a trigger only can have SQL statements which are suitable for a trigger
body.
Transition variable modifications ares allowed in the BEFORE trigger. Internal
column($trexkey$, $rowid$, concat column) or generated column modifications
are not allowed.
Not supported trigger action feature:
Result set assignment like selecting a result set assignment into a tabletype
Dynamic SQL execution like building SQL statements dynamically at the runtime
of a SQLScript
Useful Tip : We can use the below view available in SYS schema to see the list of triggers
created in SAP HANA.
TRIGGERS: Holds information about the triggers that are defined on tables and views.
Triggers has got lot of options while creating them in SAP HANA, please go through the
below link for more details:
http://help.sap.com/saphelp_hanaplatform/helpdata/en/20/d5a65575191014946db96aa
edbef5b/content.htm?frameset=/en/20/d5252d7519101493f5e662a6cda4d4/frameset.h
tm¤t_toc=/en/2e/1ef8b4f4554739959886e55d4c127b/plain.htm&node_id=209
CREATE VIEW
CREATE VIEW:
Note: The update operation is possible on database view if the object satisfies below
conditions.
Each column in the view must map to the column of a single table.
If a column in a view base table has a NOT NULL constraint without default value
the column must be included in view columns so that inserts can be performed.
An update operation on a view is allowed without this condition.
Must not contain an aggregate or analytic function in a SELECT list. For example,
the following functions are not allowed:
TOP, SET, DISTINCT operator in a SELECT list.
GROUP BY, ORDER BY clause.
Must not contain a subquery in a SELECT list.
Must not contain a sequence value (CURRVAL, NEXTVAL).
Must not contain a column view as the base view.
If base views or tables are updatable, a view on the base views or tables can also be
updatable if the above conditions are met.
Syntax: CREATE VIEW <schema_name>.<view_name> (column_name) AS <select
query>
Example:
DROP INDEX
DROP INDEX:This statement removes an index.
Examples:
DROP SCHEMA
DROP SCHEMA:
This statement is used to drop the schema from SAP HANA system.
Schema is a data base object that is used to group the different database objects
together like tables, views, synonyms, indexes and so on.
Drop option:
We have two options while dropping the schema from SAP HANA system.
CASCADE:
RESTRICT:
This option drops schema only when dependent objects doesn’t exist in the
system. System will throw an error if this option is used and dependent objects
exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified schema and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be re validated when we create same schema and same objects
under schema.
Examples:
DROP SEQUENCE
DROP SEQUENCE:
This statement is used to drop the sequence from SAP HANA database.
Drop option:
We have two options while dropping the sequence from SAP HANA system.
CASCADE: This option drops the sequence and dependent objects as well.
RESTRICT: This option drops sequence only when dependent objects doesn’t
exist in the system. System will throw an error if this option is used and
dependent objects exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified table and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be revalidated when we create same sequence in the same schema.
Example:
DROP STATISTICS
DROP STATISTICS:
If we don’t specify the type of statistics and multiple data statistics exist on the table, then all will
be dropped.
Example:
DROP SYNONYM
DROP SYNONYM:
This statement is used to drop the synonym (private and public) from SAP HANA
database.
Drop option:
We have two options while dropping the synonym from SAP HANA system.
CASCADE: This option drops the synonym and dependent objects as well.
RESTRICT: This option drops synonym only when dependent objects doesn’t
exist in the system. System will throw an error if this option is used and
dependent objects exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified table and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be revalidated when we create same sequence in the same schema.
Example:
DROP TABLE
DROP TABLE:
This statement is used to drop the table from SAP HANA system.
Drop option:
We have two options while dropping the table from SAP HANA system.
CASCADE: This option drops the table and dependent objects as well.
RESTRICT: This option drops table only when dependent objects doesn’t exist in
the system. System will throw an error if this option is used and dependent
objects exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified table and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be re validated when we create same sequence in the same
schema.
Example:
DROP TRIGGER
DROP TRIGGER:
This statement is used to drop the trigger from SAP HANA system.
Only database users having the TRIGGER privilege for the table on which the
trigger was defined are allowed to drop a trigger for that table.
Drop option:
We have two options while dropping the trigger from SAP HANA system.
CASCADE: This option drops the trigger and dependent objects as well.
RESTRICT: This option drops trigger only when dependent objects doesn’t exist
in the system. System will throw an error if this option is used and dependent
objects exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified table and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be revalidated when we create same sequence in the same schema.
Example:
DROP VIEW
DROP VIEW: This statement is used to drop the view from SAP HANA system.
Drop option:
We have two options while dropping the view from SAP HANA system.
CASCADE: This option drops the view and dependent objects as well.
RESTRICT: This option drops view only when dependent objects doesn’t exist in
the system. System will throw an error if this option is used and dependent
objects exist in the system.
When the {drop option} is not specified then system performs a non-cascaded drop. This will only
drop the specified table and dependent objects of the table will invalidated but not dropped.
The invalidated objects can be revalidated when we create same sequence in the same schema.
Example:
REFRESH STATISTICS
REFRESH STATISTICS:
Example:
RENAME COLUMN
RENAME COLUMN:
This statement is used to rename individual columns in a table to new one in SAP
HANA system.
Example:
RENAME INDEX
RENAME INDEX:
This statement is used to change the index name in SAP HANA database.
Example:
RENAME TABLE
RENAME TABLE:
Example: