Sunteți pe pagina 1din 37

SQL DDL Commands:

 ALTER FULLTEXT INDEX


 ALTER INDEX
 ALTER SEQUENCE
 ALTER TABLE
 ALTER VIRTUAL TABLE
 COMMENT ON
 CREATE FULLTEXT INDEX
 CREATE INDEX
 CREATE SCHEMA
 CREATE SEQUENCE
 CREATE STATISTICS
 CREATE SYNONYM
 CREATE TABLE
 CREATE TRIGGER
 CREATE VIEW
 DROP INDEX
 DROP SCHEMA
 DROP SEQUENCE
 DROP STATISTICS
 DROP SYNONYM
 DROP TABLE
 DROP TRIGGER
 DROP VIEW
 REFRESH STATISTICS
 RENAME COLUMN
 RENAME INDEX
 RENAME TABLE

ALTER FULLTEXT INDEX:

 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.

Syntax: ALTER FULLTEXT INDEX <schema_name>.<index_name> <index_options>

Parameters:

We can use the below parameters while altering the full text index in SAP HANA.

FUZZY SEARCH INDEX (on/off):


 Defines if a fuzzy search index will be used.
 ON switches on the fuzzy search index, and OFF turns the fuzzy search index off.

PHRASE INDEX RATIO:

 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:

1. Alter the index SS_ORDERS_DATA_PROD_CODE and add fuzzy search with


phrase index ration 0.8

Ans: ALTER FULLTEXT INDEX SCHEMA_NAME.SS_ORDERS_DATA_PROD_CODE


PHRASE RATIO 0.8
FUZZY SEARCH INDEX ON

2. Suspend queue for index SS_ORDERS_DATA_PROD_CODE

Ans: ALTER FULLTEXT INDEX SCHEMA_NAME.SS_ORDERS_DATA_PROD_CODE


SUSPEND QUEUE

3. Activate queue for index SS_ORDERS_DATA_PROD_CODE

Ans: ALTER FULLTEXT INDEX SCHEMA_NAME.SS_ORDERS_DATA_PROD_CODE


ACTIVATE QUEUE

4. Flush out the queue for index SS_ORDERS_DATA_PROD_CODE.

Ans: ALTER FULLTEXT INDEX SCHEMA_NAME.SS_ORDERS_DATA_PROD_CODE


FLUSH QUEUE

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:

1. Rebuild the index for SS_ORDERS_DATA_ORD_NUM in SAP HANA.

Ans: ALTER INDEX SCHEMA_NAME.SS_ORDERS_DATA_ORD_NUM REBUILD

ALTER SEQUENCE
ALTER SEQUENCE:

 This statement is used to alter the parameters of sequence generator.

Syntax: ALTER SEQUENCE <schema_name>.<sequence_name> <restart_with>


[<parameter_list>][ RESET BY <sub_query>]

Parameters:

 We can use different parameters while altering sequence in SAP HANA. They are

START WITH:

 The starting sequence value.


 If you do not specify a value for the START WITH clause, MINVALUE is used for
ascending sequences and MAXVALUE is used for descending sequences.

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:

 The maximum value that can be generated by the sequence.


 <max_value> must be between -4611686018427387903 and
4611686018427387902.

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:

 During the restart of the database, database automatically executes the


<subquery> and the sequence value is restarted with the returned value.

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.

Ans: ALTER SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM MAXVALUE


10000 NO MINVALUE

2. Alter sequence SCHEMA_NAME.SEQUENCE_ORD_NUM to add reset condition.

Ans: ALTER SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM


RESET BY SELECT MAX(CUST_NO)
FROM SCHEMA_NAME.CUST_INFO

3. Alter sequence SCHEMA_NAME.SEQUENCE_ORD_NUM to change the incremental


value to 3, and specify that the sequence will not restart upon reaching its
maximum or minimum value.

Ans: ALTER SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM


INCREMENT BY 3 NO CYCLE

4. Alter sequence SCHEMA_NAME.SEQUENCE_ORD_NUM to restart the sequence


from 1.

Ans: ALTER SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM INCREMENT


RESTART WITH 1

ALTER TABLE
ALTER TABLE:

 This statement is used to change the table definition which has been set using
CREATE TABLE statement.

Syntax: ALTER TABLE <schema_name>.<table_name> <alter_clause>

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:

1. Alter table to add additional column.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD (QUANTITY DECIMAL(15,2))

2. Alter table to drop column.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DROP (QUANTITY)


3. Alter table to change the data type of an existing column.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ALTER (QUANTITY DECIMAL(35,5)


)

4. Alter table to add primary key.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD PRIMARY KEY (ORDER_NUM


BER,CUST_NO)

5. Alter table to drop primary key.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DROP PRIMARY KEY

6. Alter table to add primary key constraint.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD CONSTRAINT primary_key P


RIMARYKEY(ORDER_NUMBER,CUST_NO)

7. Alter table to drop primary key constraint.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DROP CONSTRAINT primary_key

8. Alter table to add unique constraint.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD CONSTRAINT unique_key UN


IQUE (ORDER_NUMBER)

9. Alter table to drop unique constraint.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DROP CONSTRAINT unique_key

10. Alter table to add default value to the existing column.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ALTER (CUST_NO NVARCHAR(10)


DEFAULT ‘C_9999’)

11. Alter table to change the storage from COLUMN to ROW

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ROW

12. Alter table to change the storage from ROW to COLUMN.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA COLUMN


13. Alter table to set the pre-load flags for specific columns.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA PRELOAD (ORDER_NUMBER,CUST_


NO)

14. Alter table to change the UNLOAD priority.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA UNLOAD PRIORITY 2

Note: UNLOAD PRIORITY can be anything between 0 and 9 where 0 means not
unloadable and 9 means earliest unload.

15. Alter table to disable to delta logging.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DISABLE DELTA LOG

16. Alter table to change the location from hana in-memory to extended storage.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA USING EXTENDED STORAGE

17. Alter table to change the location from extended storage to hana in-memory

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA NOT USING EXTENDED STORAGE

18. Alter table to add hash partitioning.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA PARTITION BY HASH(ORDER_NU


MBER,CUST_NO) PARTITIONS 4

19. Alter table to drop hash partitioning

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA MERGE PARTITIONS

20. Alter table to create range partitioning.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA PARTITION BY RANGE


(ORDER_NUMBER) (PARTITION VALUE<=30000, PARTITION OTHERS)

21. Alter table to add additional range partition.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD PARTITION 30001<= VALUE


S <100000

22. Alter table to add the schema flexibility


Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ENABLE SCHEMA FLEXIBILITY

23. Alter table to drop the replicas in all index server locations.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DROP REPLICA AT ALL LOCATIONS

24. Alter table to move replica from one index server to another.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA MOVE


REPLICA FROM ‘HOST_NAME:30040’ TO ‘HOST_NAME:30042’

25. Alter table to add replica at one location.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ADD REPLICA AT ‘HOST_NAME:300


40’

26. Alter table to disable/stop automatic delta merge.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA DISABLE AUTOMERGE

27. Alter table to enable the delta merge.

Ans: ALTER TABLE SCHEMA_NAME.ORDERS_DATA ENABLE AUTOMERGE

Note: We can run also run one time delta using the below statement.

Ans: MERGE DELTA OF SCHEMA_NAME.ORDERS_DATA

ALTER VIRTUAL TABLE


ALTER VIRTUAL TABLE:

 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:

 ALTER VIRTUAL TABLE <schema_name>.<table_name> SET|UNSET


PROPERTY
 ALTER VIRTUAL TABLE <schema_name>.<table_name> ALTER
<column_name>SET|UNSET PROPERTY

Example:
1. Alter virtual table SCHEMA_NAME.VT_ORDERS_DATA to set the property name1
to value 1.

ANs: ALTER VIRTUAL TABLE SCHEMA_NAME.VT_ORDERS_DATA SET PROPERTY


‘name1’ = ‘value1’

2. Alter virtual table SCHEMA_NAME.VT_ORDERS_DATA to update the property


name1 value to value2

Ans: ALTER VIRTUAL TABLE SCHEMA_NAME.VT_ORDERS_DATA SET PROPERTY


‘name1’ = ‘value2’

3. Alter virtual table SCHEMA_NAME.VT_ORDERS_DATA to unset the property value


to null.

Ans: ALTER VIRTUAL TABLE SCHEMA_NAME.VT_ORDERS_DATA UNSET PROPERTY


‘name1’

4. Alter virtual table SCHEMA_NAME.VT_ORDERS_DATA to set the property name1


value to value1 for column ORDER_NUMBER.

Ans: ALTER VIRTUAL TABLE SCHEMA_NAME.VT_ORDERS_DATA ALTER ORDER_NUMBE


R SET PROPERTY ‘name1’ = ‘value1’

COMMENT ON
COMMENT ON:

 This statement is used to add descriptive comments to tables, views or their


individual columns in SAP HANA system.
 Comments are a useful way to record a meaningful description of schema
tables/views, and their columns, for future reference.
 We can also remove comments using same statement.

Syntax:

 COMMENT ON {TABLE|VIEW} <schema_name>.<object_name> IS


<comment>
 COMMENT ON COLUMN <schema_name>.<table/view name>.<column_name>
IS <comment>

Examples:

1. Create comment on ORDERS_DATA table in SCHEMA_NAME schema.

Ans: COMMENT ON TABLE SCHEMA_NAME.ORDERS_DATA IS ‘Sales Orders Table’


2. Create comment on ORDERS_VIEW view in SCHEMA_NAME

Ans: COMMENT ON VIEW SCHEMA_NAME.ORDERS_VIEW IS ‘View on Sales Orders


Table’

3. Create comment on ORDER_NUMBER column from ORDERS_DATA table in


SCHEMA_NAME schema.

Ans: COMMENT ON COLUMN SCHEMA_NAME.ORDERS_DATA.ORDER_NUMBER IS ‘Sale


s Order Number’

4. Remove comment on ORDERS_DATA table in SCHEMA_NAME schema.

Ans: COMMENT ON TABLE SCHEMA_NAME.ORDERS_DATA IS NULL


COMMENT ON COLUMN SCHEMA_NAME.ORDERS_DATA.ORDER_NUMBER IS NUL
L

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.

CREATE FULLTEXT INDEX


CREATE FULLTEXT INDEX:

 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

Syntax: CREATE FULL TEXT INDEX <index_name> ON


<schema_name>.<table_name> (column_name) <full_text_parameters>

Different Parameters that can be used to create Full text Index are:

LANGUAGE COLUMN:

 We can define what the language column using this parameter.


LANGUAGE DETECTION:

 Using this function, we can define what languages to consider.

MIME TYPE COLUMN:

 Defines the column where the mime-type of a document is specified.

FUZZY SEARCH INDEX (on/off):

 Specifies whether a fuzzy search index should be used.

PHRASE INDEX RATIO: Specifies the percentage of the phrase index. Value must be
between 0.0 and 1.0

CONFIGURATION:

 The path to a custom configuration file for text analysis.

SEARCH ONLY (on/off):

 Defines if the original document should be stored or only the search results.
 When set to ON the original document content is not stored.

FAST PREPROCESS (on/off):

 If set to ON, fast preprocessing is used, i.e. linguistic searches are not possible.

TEXT ANALYSIS (on/off):

 Enables text analysis capabilities on the indexed column.


 Text analysis can extract entities such as persons, products, or places from
documents, which are stored in a new table.

MIME TYPE:

 The default mime type used for preprocessing.


 The value must be a valid mime type, for example ‘cf
M_TEXT_ANALYSIS_MIME_TYPES’.

TOKEN SEPARATORS:

 A set of characters used for token separation. Only ASCII characters are
considered.
SYNC[HRONOUS]:

 Creates a synchronous fulltext index.

ASYNC[HRONOUS]:

 Creates an asynchronous fulltext index.

TEXT MINING (on/off):

 Enables text mining capabilities on the indexed column. Text mining provides
functionality that can compare documents by examining the terms used within
them.

TEXT MINING CONFIGURATION:

 The path to a custom configuration file for text mining. If not specified,
DEFAULT.textminingconfig is used.

Example:

1. Create Full text index on prod code in ORDERS_DATA table.

Ans: CREATE FULLTEXT INDEX SS_ORDERS_DATA_PROD_CODE


ON SCHEMA_NAME.ORDERS_DATA (ORDER_NUMBER)
FUZZY SEARCH INDEX OFF
SYNC LANGUAGE DETECTION (‘EN’,’DE’)

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.

Syntax: CREATE {UNIQUE} | [BTREE|CPBTREE] INDEX <index_name> ON


<schema_name>.<table_name> (<column_names>,<order_by>) <global order>
<fillfactor>
We have three index types in SAP HANA, they are

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:

 SAP HANA creates CPBTREE index on specified table and column.


 CPBTREE stands for Compressed Prefix BTREE.
 This index tree is based on pkB-tree.
 CPB+-tree is a very small index because it uses ‘partial key’ that is only part of
full key in index nodes.
 CPB+-tree shows better performance than B+-Tree for larger keys.

Column Order:

 This is used to define the sorting order.


 We can either define ASC (ascending) or DESC (Descending). The default option
is ASC.

Global Order:

 This is also same as column order.


 Column order is for individual column where global order is for all the columns
involved in index.
 We cannot use both column order and global order at the same time.

Fillfactor:

 This option specifies how each node of a new index is filled.


 It is a percentage value of integer from 50 to 100, and the default value is 90.

Examples:
1. Create BTREE index on table ORDERS_DATA for column ORDER_NUMBER with
descending order.

Ans: CREATE BTREE INDEX SS_ORDERS_DATA_ORD_NUM ON SCHEMA_NAME.ORDER


S_DATA (ORDER_NUMBER DESC)

2. Create CPBTREE index on table ORDERS_DATA for column ORDER_NUMBER with


global ascending order.

Ans: CREATE CPBTREE INDEX SS_ORDERS_DATA_ORD_NUM ON SCHEMA_NAME.ORD


ERS_DATA (ORDER_NUMBER) ASC

3. Create UNIQUE BTREE index on table ORDERS_DATA for column ORDER_NUMBER


with global ascending order and fill factor 95.

Ans: CREATE UNIQUE BTREE INDEX SS_ORDERS_DATA_ORD_NUM ON SCHEMA_NAM


E.ORDERS_DATA (ORDER_NUMBER)ASC 95

4. Create UNIQUE CPBTREE index on table ORDERS_DATA for column


ORDER_NUMBER with global descending order and fill factor 100.

Ans: CREATE UNIQUE CPBTREE INDEX SS_ORDERS_DATA_ORD_NUM ON SCHEMA_N


AME.ORDERS_DATA (ORDER_NUMBER)DESC 100

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:

 This statement is used to create schema in SAP HANA database.

Syntax: CREATE SCHEMA <schema_name> OWNED BY <user_name>

OWNED BY user will have full rights on the schema.


If it is not mentioned, then logged on user will be the owner of the schema.

Examples:

1. Create schema ‘SCHEMA_NAME’ and make owner as ‘SYSTEM’ user.


Ans: CREATE SCHEMA SCHEMA_NAME OWNED BY SYSTEM

2. Create schema ‘SCHEMA_NAME’ and make owner as current user.

Ans: CREATE SCHEMA SCHEMA_NAME

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:

 This statement is used to create a sequence in SAP HANA Database.


 A sequence is used to generate unique integers by multiple users.
 CURRVAL is used to get the current value of the sequence and NEXTVAL is used
to get the next value of the sequence.

CURRVAL is only valid after calling NEXTVAL in a session.

We can use CURRVAL and NEXTVAL only in:

 The select list of a SELECT statement which is not contained in a subquery, or


view
 The select list of a subquery in an INSERT statement
 The VALUES clause of an INSERT statement
 The SET clause of an UPDATE statement

We cannot use CURRVAL and NEXTVAL in:

 The WHERE clause of a SELECT statement


 A subquery in a DELETE, SELECT, UPDATE, REPLACE or UPSERT statement
 A SELECT statement in a CREATE VIEW statement
 A SELECT statement with the DISTINCT operator
 A SELECT statement with a GROUP BY clause
 A SELECT statement with the UNION, INTERSECT, or MINUS set operator
 The DEFAULT value of a column in a CREATE TABLE or ALTER TABLE statement

Syntax: CREATE SEQUENCE <schema_name>.<sequence_name>


[<parameters_list>] [RESET BY <sub_query>]

Parameters:
 We can use different parameters while creating sequence in SAP HANA. They are

START WITH:

 The starting sequence value.


 If you do not specify a value for the START WITH clause, MINVALUE is used for
ascending sequences and MAXVALUE is used for descending sequences.

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:

 The maximum value that can be generated by the sequence.


 <max_value> must be between -4611686018427387903 and
4611686018427387902.

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:

 During the restart of the database, database automatically executes the


<subquery> and the sequence value is restarted with the returned value.

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. Create sequence with name SEQUENCE_ORD_NUM in SCHEMA_NAME schema.

Ans: CREATE SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM START WITH 30001


INCREMENT BY 1

2. Get the next value from sequence

Ans: SELECT SCHEMA_NAME.SEQUENCE_ORD_NUM.NEXTVAL FROM DUMMY

3. Get the current value from sequence

Ans: SELECT SCHEMA_NAME.SEQUENCE_ORD_NUM.CURRVAL FROM DUMMY

4. Use the next value of sequence while inserting data into table.

Ans: INSERT INTO SCHEMA_NAME.ORDERS_DATAVALUES(SCHEMA_NAME.SEQUENCE


_ORD_NUM.NEXTVAL,’C123′,’PROD_345′,50)

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.

Syntax: CREATE STATISTICS <statistics_name> ON


<schem_name>.<table_name>.<column_names> [<properties>]

Data statistics can be created either on tables or individual columns.


Based on the source we select, we need to select the relevant properties.

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:

 The mathematical constraint used to build a histogram.


 This parameter can only be specified when TYPE is HISTOGRAM.
 Only two types of histograms are supported:
o q-optimal
o maxdiff

Default:

 MAXDIFF for virtual tables and QOPTIMAL for other data sources.

BUCKETS:

 The maximum number of data buckets to be used in the histogram.


 This parameter can only be specified when TYPE is HISTOGRAM.

Default:

 Automatically determined by the histogram algorithm in use.

QERROR:

 The Q error used to build the q-optimal histogram.


 This parameter can only be specified when TYPE is HISTOGRAM, and
CONSTRAINT is QOPTIMAL.

Default:

 Automatically determined by the histogram build algorithm in use.

QTHETA:

 A lower-bound on the frequencies for which a q error constraint is applied when


building a q-optimal histogram.
 This parameter can only be specified when TYPE is HISTOGRAM, and
CONSTRAINT is QOPTIMAL.

Default:

 Automatically determined by the histogram build algorithm in use.

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:

 Automatically determined by the histogram build algorithm in use.

MEMORY:

 Similar to the MEMORY PERCENT parameter above, the MEMORY parameter is


used to limit the memory for data statistics objects.
 <memory_bytes> specifies the maximum amount of memory, in bytes, which
can be used for the data statistics object.

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:

1. Create RECORD COUNT STATISTICS on virtual table

Ans: CREATE STATISTICS PRODUCTS ON SCHEMA_NAME.VT_PRODUCTS TYPE RECO


RD COUNT

2. Create histogram statistics on column ORD_NUMBER in ORDERS_DATA table with


100 buckets

Ans: CREATE STATISTICS ORDER_NUMBER ON SCHEMA_NAME.ORDERS_DATA


(ORD_NUMBER) TYPE HISTOGRAM BUCKETS 100

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:

1. Create synonym ORDER_INFO on table ORDERS_DATA in SCHEMA_NAME


schema.

Ans: CREATE SYNONYM SCHEMA_NAME.ORDER_INFO FOR SCHEMA_NAME.ORDERS_


DATA

2. Create public synonym ORDER_INFO on table ORDERS_DATA in SCHEMA_NAME


schema.

Ans: CREATE PUBLIC SYNONYM SCHEMA_NAME.ORDER_INFO FOR SCHEMA_NAME.O


RDERS_DATA

CREATE TABLE
CREATE TABLE:

 This statement is used to create physical table in SAP HANA.


 Tables are created without data except when <as_table_subquery> or
<like_table_clause> is used along with the WITH DATA option.
 The CREATE VIRTUAL TABLE is an extension of the CREATE TABLE statement.
 It provides a way to access an existing table/view on a remote source from an
SAP HANA instance (Smart Data Access).
 The list of remote columns is automatically imported into the virtual table.

Syntax: CREATE <table_type> TABLE <schema_name>.<table_name> (<column


names> <data types>) <parameters>

We can create different types of tables in SAP HANA. They are,

 COLUMN
 ROW
 HISTORY COLUMN
 GLOBAL TEMPORARY
 GLOBAL TEMPORARY COLUMN
 LOCAL TEMPORARY
 LOCAL TEMPORARY COLUMN
ROW, COLUMN:

 Defines the type of table storage organization.


 The default value is ROW. When we write just CREATE TABLE statement, system
creates ROW table by default in SAP HANA.
 We can change this setting by modifying the parameters to COLUMN as shown
below.
 Open ‘Administration Console’ → click on ‘Configuration’ → expand
‘indexserver.ini’ → expand ‘sql’ → change ‘default_table_type’ value from ‘row’ to
‘column’.

 This will make the default table type as ‘COLUMN’ instead of ROW.

HISTORY COLUMN:

 Creates a table with a particular transaction session type called ‘HISTORY’.


 Tables with session type HISTORY support time travel queries.
 Time travel queries are queries against historical states of the database.

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.

Supported operations on Global Temporary Table:

 Create with or without a primary key


 Add or drop primary key
 Add or drop unique
 Rename table
 Add, alter, rename or drop column
 Truncate
 Drop
 Create or Drop view on top of global temporary table
 Create synonym
 Select
 Select into or Insert
 Delete
 Update
 Upsert or Replace

GLOBAL TEMPORARY COLUMN:

 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.

Supported operations on Global Temporary Column Table:


 Create without a primary key
 Truncate
 Drop
 Create or Drop view on top of global temporary column table
 Create synonym
 Select
 Select into or Insert

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.

Supported operations on Local Temporary Table:

 Create without a primary key


 Truncate
 Drop
 Select
 Select into or Insert
 Delete
 Update
 Upsert or Replace

LOCAL TEMPORARY COLUMN:

 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.

Supported operations on Local Temporary Table:

 Create without a primary key


 Truncate
 Drop
 Select
 Select into or Insert

VIRTUAL:

 Creates a virtual table based on an existing table/view inside a remote source.

Examples:

1. Create a column table with two columns.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER,CUST_NO NVARCHAR(10))

2. Create a ROW table with two columns.

Ans: CREATE ROW TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER,CUST_NO NVARCHAR(10))

3. Create a column table with primary key.

Ans:

 CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10))
 CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA
(ORDER_NUMBER INTEGER,CUST_NONVARCHAR(10),PRIMARY KEY (ORDER_
NUMBER,CUST_NO))

4. Create a column table like another table without data

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA_COPY LIKE SCHEMA_N


AME.ORDERS_DATA

5. Create a column table like another table with data

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA_COPY LIKE SCHEMA_N


AME.ORDERS_DATA WITH DATA

6. Create a column table using sub query result without data.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA_COPY AS (SELECT * FR


OM SCHEMA_NAME.ORDERS_DATA)WITH NO DATA
7. Create a column table using sub query result with data.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA_COPY AS (SELECT * FR


OM SCHEMA_NAME.ORDERS_DATA)WITH DATA

8. Create a column table with foreign key relationship with other table.

Ans:

 CREATE COLUMN TABLE SCHEMA_NAME.CUST_INFO


(CUST_NO INTEGER PRIMARY KEY,CUST_NAMENVARCHAR(50))
 CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA
(ORDER_NUMBER INTEGER PRIMARY KEY,
CUST_NOINTEGER,FOREIGN KEY (CUST_NO) REFERENCES SCHEMA_NAME.C
UST_INFO ON UPDATE CASCADE)

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.

9. Create a column table with partitioning clause.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10) PARTITION BY
HASH(ORDER_NUMBER) PARTITIONS 2)

10. Create a virtual table on remote source.

Ans: CREATE VIRTUAL TABLE SCHEMA_NAME.VT_ORDERS_DATA AT MSSQL.SCHEMA_


NAME.DBO.ORDERS_DATA

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.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10)) USING EXTEN
DED STORAGE

12. Create a table in extended storage with delta enabled

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10)) USING EXTEN
DED STORAGE ENABLE DELTA

13. Create a column table with dynamic columns using GENERATED ALWAYS

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10) GENERATED
ALWAYS AS CONCAT(‘C_’,SUBSTRING(ORDER_NUMBER,LENGTH(ORDER_NUMBER)-
2)))

Note: GENERATED ALWAYS function is used to populate data into a column


automatically whenever we insert record into that table. Here we are trying to populate
CUST_NO as last three digits and concatenating it with ‘C_’.

14. Create a columns table by using IDENTITY for GENERATED ALWAYS.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY GENERATED
ALWAYS AS IDENTITY (START WITH 30000
INCREMENT BY 1),CUST_NO NVARCHAR(10))

IDENTITY is similar to sequence that can be used for populating unique number to use it as
primary key.

15. Create a column table and replicate in all index servers.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10))
REPLICA AT ALL LOCATIONS

16. Create a column table with schema flexibility.

Ans: CREATE COLUMN TABLE SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER INTEGER PRIMARY KEY,CUST_NONVARCHAR(10)) WITH SCHEM
A FLEXIBILITY
Insert Statement: INSERT INTO SCHEMA_NAME.ORDERS_DATA
(ORDER_NUMBER,CUST_NO,QUANTITY) VALUES(1234,’C567′,50)

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.

The limitations with current trigger in SAP HANA Database are:

 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.

Syntax: CREATE TRIGGER <schema_name>.<trigger_name> <trigge_action_time>


<trigger event list> ON <table/view> [REFERENCING <transaction>] [for each
row] BEGIN
[<trigger_decl_list>] [<proc_handler_list>] <trigger_stmt_list>
END

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&current_toc=/en/2e/1ef8b4f4554739959886e55d4c127b/plain.htm&node_id=209

CREATE VIEW
CREATE VIEW:

 This statement is used to create database view in SAP HANA system.


 This can be created on physical tables or another database views.

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:

1. Create database view on table ORDERS_DATA for last 5 years orders in


SCHEMA_NAME schema.

Ans: CREATE VIEW SCHEMA_NAME.ORDERS_VIEW (ORDER_NUMBER, CUST_NO,


PROD_NO, QUANTITY) AS SELECTORDER_NUMBER,
CUST_NO,
PROD_NO,
QUANTITY
FROM SCHEMA_NAME.ORDERS_DATA WHERE YEAR(ORDERED_DATE)
>= YEAR(CURRENT_DATE)-5

DROP INDEX
DROP INDEX:This statement removes an index.

Syntax: DROP INDEX <schema>.<index_name>

Examples:

1. Drop index SS_ORDERS_DATA_ORD_NUM created on ORDERS_DATA table in


SCHEMA_NAME schema.

Ans: DROP INDEX SCHEMA_NAME.SS_ORDERS_DATA_ORD_NUM

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.

Syntax: DROP SCHEMA <schema_name> {drop_option}

Drop option:

 We have two options while dropping the schema from SAP HANA system.

CASCADE:

 This option drops the schema and dependent objects as well.

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:

1. Drop schema SCHEMA_NAME with CASCADE option.

Ans: DROP SCHEMA SCHEMA_NAME CASCADE

2. Drop schema SCHEMA_NAME with RESTRICT option.

Ans: DROP SCHEMA SCHEMA_NAME RESTRICT

3. Drop schema SCHEMA_NAME without drop option.

Ans: DROP SCHEMA SCHEMA_NAME

DROP SEQUENCE
DROP SEQUENCE:

 This statement is used to drop the sequence from SAP HANA database.

Syntax: DROP SEQUENCE <schema_name>.<sequence_name> {drop_option}

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:

1. Drop sequence SCHEMA_NAME.SEQUENCE_ORD_NUM with CASCADE option.


Ans: DROP SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM CASCADE

2. Drop sequence SCHEMA_NAME.SEQUENCE_ORD_NUM with RESTRICT option.

Ans: DROP SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM RESTRICT

3. Drop sequence SCHEMA_NAME.SEQUENCE_ORD_NUM without drop option.

Ans: DROP SEQUENCE SCHEMA_NAME.SEQUENCE_ORD_NUM

DROP STATISTICS
DROP STATISTICS:

 This statement is used to drop the statistics created on tables or individual


columns in SAP HANA system.

Syntax: DROP STATISTICS <statistics_name> |ON <schema_name>.<table_name>


(<column_name>) [TYPE HISTOGRAM|SIMPLE|ALL]

If we don’t specify the type of statistics and multiple data statistics exist on the table, then all will
be dropped.

Example:

1. Drop the statistics ORDER_NUMBER created on ORDER_NUMBER column in


ORDERS_DATA table of type HISTOGRAM.

Ans: DROP STATISTICS ON SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER) TYPE HISTOGRAM

2. Drop statistics with name PRODUCTS

Ans: DROP STATISTICS PRODUCTS

DROP SYNONYM
DROP SYNONYM:

 This statement is used to drop the synonym (private and public) from SAP HANA
database.

Syntax: DROP SYNONYM <schema_name>.<synonym_name> {drop_option}

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:

1. Drop synonym SCHEMA_NAME.ORDER_INFO with CASCADE option.

Ans: DROP SYNONYM SCHEMA_NAME.ORDER_INFO CASCADE

DROP PUBLIC SYNONYM SCHEMA_NAME .ORDER_INFO CASCADE

2. Drop synonym SCHEMA_NAME.ORDER_INFO with RESTRICT option.

Ans: DROP SYNONYM SCHEMA_NAME.ORDER_INFO RESTRICT

DROP PUBLIC SYNONYM SCHEMA_NAME .ORDER_INFO RESTRICT

3. Drop synonym SCHEMA_NAME.ORDER_INFO without drop option.

Ans: DROP SYNONYM SCHEMA_NAME.ORDER_INFO

DROP PUBLIC SYNONYM SCHEMA_NAME .ORDER_INFO

DROP TABLE
DROP TABLE:

 This statement is used to drop the table from SAP HANA system.

Syntax: DROP TABLE <schema_name>.<table_name> {drop_option}

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:

1. Drop table ORDERS_DATA with CASCADE option.

Ans: DROP TABLE SCHEMA_NAME.ORDERS_DATA CASCADE

2. Drop table ORDERS_DATA with RESTRICT option.

Ans: DROP TABLE SCHEMA_NAME.ORDERS_DATA RESTRICT

3. Drop table ORDERS_DATA without drop option.

Ans: DROP TABLE SCHEMA_NAME.ORDERS_DATA

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.

Syntax: DROP TRIGGER <schema_name>.<trigger_name> {drop_option}

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:

1. Drop trigger SCHEMA_NAME.TRIGGER_ORDER_NUM with CASCADE option.

Ans: DROP TRIGGER SCHEMA_NAME.TRIGGER_ORDER_NUM CASCADE

2. Drop trigger SCHEMA_NAME.TRIGGER_ORDER_NUM with RESTRICT option.


Ans: DROP TRIGGER SCHEMA_NAME.TRIGGER_ORDER_NUM RESTRICT

3. Drop trigger SCHEMA_NAME.TRIGGER_ORDER_NUM without drop option.

Ans: DROP TRIGGER SCHEMA_NAME.TRIGGER_ORDER_NUM

DROP VIEW
DROP VIEW: This statement is used to drop the view from SAP HANA system.

Syntax: DROP VIEW <schema_name>.<view_name> {drop_option}

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:

1. Drop view SCHEMA_NAME.ORDERS_VIEW with CASCADE option.

Ans: DROP VIEW SCHEMA_NAME.ORDERS_VIEW CASCADE

2. Drop view SCHEMA_NAME.ORDERS_VIEW with RESTRICT option.

Ans: DROP VIEW SCHEMA_NAME.ORDERS_VIEW RESTRICT

3. Drop view SCHEMA_NAME.ORDERS_VIEW without drop option.

Ans: DROP VIEW SCHEMA_NAME.ORDERS_VIEW

REFRESH STATISTICS
REFRESH STATISTICS:

 This statement is used to refresh the statistics created on tables or individual


columns in SAP HANA system.

Syntax: REFRESH STATISTICS <statistics_name> |ON


<schema_name>.<table_name> (<column_name>) [TYPE HISTOGRAM|SIMPLE|ALL]
If we don’t specify the type of statistics and multiple data statistics exist on the table, then all will
be refreshed.

Example:

1. Refresh the statistics ORDER_NUMBER created on ORDER_NUMBER column in


ORDERS_DATA table of type HISTOGRAM.

Ans: REFRESH STATISTICS ON SCHEMA_NAME.ORDERS_DATA


(ORDER_NUMBER) TYPE HISTOGRAM

2. Refresh statistics with name PRODUCTS

Ans: REFRESH STATISTICS PRODUCTS

RENAME COLUMN
RENAME COLUMN:

 This statement is used to rename individual columns in a table to new one in SAP
HANA system.

Syntax: RENAME COLUMN <schema_name>.<table_name>.<column_name> TO


<new_column_name>

Example:

1. Rename column ORDER_NUMBER in table ORDERS_DATA to ORDER_NO

Ans: RENAME COLUMN SCHEMA_NAME.ORDERS_DATA.ORDER_NUMBER TO ORDER_N


O

RENAME INDEX
RENAME INDEX:

 This statement is used to change the index name in SAP HANA database.

Syntax: RENAME INDEX <schema_name>.<index_name> TO <new_index_name>

Example:

1) Rename the index name SS_ORDERS_DATA_ORD_NUM to


SS_ORDERS_DATA_ORD_NUMBER.

Ans: RENAME INDEX SCHEMA_NAME.SS_ORDERS_DATA_ORD_NUM TO SS_ORDERS_


DATA_ORD_NUMBER

RENAME TABLE
RENAME TABLE:

 This statement is used to rename table in SAP HANA system.

Syntax: RENAME TABLE <schema_name>.<table_name> TO <new_table_name>

Example:

1. Rename the table name ORDERS_DATA to ORDERS_DATA_NEW

Ans: RENAME TABLE SCHEMA_NAME.ORDERS_DATA TO ORDERS_DATA_NEW

S-ar putea să vă placă și