Tuesday 7 November 2017

SAP HANA: ALTER statements

To Create Table:

   create column table "KABIL_PRACTICE"."DEMO"
   (
   "ID" integer,
   "NAME" Nvarchar(35)
   );

To View the data from the table:

   select * from "KABIL_PRACTICE"."DEMO";

To alter Column Store to Row Store table:

   Alter table "KABIL_PRACTICE"."DEMO" Row;

To alter Row Store to Column Store table:

   Alter table "KABIL_PRACTICE"."DEMO" Column;

Alter table to add an additional column.          

   Alter table "KABIL_PRACTICE"."DEMO" Add ("CITY" Nvarchar(35));

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

   Alter table "KABIL_PRACTICE"."DEMO" Alter ("CITY" varchar(35));

Note:

·         For column table, only increasing the size of a column data type is allowed to prevent data loss.
·         For example, changing from NVARCHAR (20) to NVARCHAR (10) or from INTEGER to TINYINT raises an error.
·         For row table, only increasing the size of VARCHAR and NVARCHAR type column is allowed. Other data type changes are not allowed.

Example:

To add a Salary column:

   Alter table "KABIL_PRACTICE"."DEMO" Add ("Salary" Decimal(10,2));

To alter a Salary Column data type:

   Alter table "KABIL_PRACTICE"."DEMO" Alter ("Salary" Decimal(15,2));
            It raises an error like feature not supported: cannot change the field length: Salary

To Alter Existing Column with NOT NULL

   Alter table "KABIL_PRACTICE"."DEMO" Alter ("ID" integer NOT NULL);
   Adding a NOT NULL constraint to an existing column is allowed if either of the following cases are true:
·         The table is empty.
·         The default value is specified when the table contains data.
·         The table does not contain a NULL-value in that column.

To Add Primary Key for Existing table column

   Alter table "KABIL_PRACTICE"."DEMO" Add primary key ("ID");

To Add Primary Key for Multiple Columns in an Existing table

   Alter table "KABIL_PRACTICE"."DEMO" Add primary key ("ID","NAME");

To Drop Primary Key for Existing table column

   Alter table "KABIL_PRACTICE"."DEMO" drop primary key;

Alter table to Drop column.                           

   Alter table "KABIL_PRACTICE"."DEMO" Drop ("CITY");

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.

Examples:

To create COMMENT ON for DEMO table in “KABIL_PRACTICE” Schema

   COMMENT ON TABLE "KABIL_PRACTICE"."DEMO" IS 'DEMO Table for Alter Statements';
Note:
            we can see this comment by Right click your table from the corresponding schema and click open definition. A new tab will open from that select Further Properties, you can see the comment of your table.

To Remove comment on Table

   COMMENT ON TABLE "KABIL_PRACTICE"."DEMO" IS null;

To create COMMENT ON ID Column from DEMO table in “KABIL_PRACTICE” Schema

   COMMENT ON COLUMN "KABIL_PRACTICE"."DEMO"."ID" is 'EMPLOYEE_ID';
Note:
            we can see this comment by Right click your table from the corresponding schema and click open definition. A new tab will open with that comment will be shown in the corresponding column.

To Remove comment on Column

   COMMENT ON COLUMN "KABIL_PRACTICE"."DEMO"."ID" is null;

To Rename Column

   Rename column "KABIL_PRACTICE"."DEMO"."ID"  To "E_ID";

To Rename Table


   Rename Table "KABIL_PRACTICE"."DEMO" To "DEMO_TABLE";

Thank You for Visiting My Blog...
Share Your Comments...

12 comments:

  1. Mesmerized article written on this blog with other relevant information. It is straight to the point that how we can improve our skills as well as how we can be represented to a new stream of professionalism.โต๊ะหมู่บูชา ราคา

    ReplyDelete

  2. Thanks for sharing the descriptive information on SAP HANA tutorial. It’s really helpful to me since I'm taking SAP HANA training. Keep doing the good work and if you are interested to know more on SAP HANA, do check this SAP HANA tutorial.:-https://www.youtube.com/watch?v=-EkGfy7kBWQ

    ReplyDelete
  3. It is very helpful. Thank you

    ReplyDelete
  4. Perfect and thank you for crisp examples

    ReplyDelete
  5. My name is Leah Brown, I'm a happy woman today? I told myself that any loan lender that could change my life and that of my family after having been scammed separately by these online loan lenders, I will refer to anyone who is looking for loan for them. It gave me and my family happiness, although at first I had a hard time trusting him because of my experiences with past loan lenders, I needed a loan of $300,000.00 to start my life everywhere as single mother with 2 children, I met this honest and God fearing online loan lender Gain Credit Loan who helped me with a $300,000.00 loan, working with a loan company Good reputation. If you are in need of a loan and you are 100% sure of paying the loan please contact (gaincreditloan1@gmail.com)

    ReplyDelete
  6. online digital marketing course
    We at ikxbay are committed to provide industry ready and relevant skill set training to freshers and professionals. Attend 1st 2 live classes for FREE!!

    ReplyDelete
  7. Wonderful explanation on SAP HANA topics Very good blog for SAP HANA modules and cool blog with Superb information on SAP Training modules and kindly do for SAP other modules too..

    ReplyDelete
  8. This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post!
    Definition of SAP

    ReplyDelete


  9. IntelliMindz is the best IT Training in Bangalore with placement, offering 200 and more software courses with 100% Placement Assistance.

    SAP HANA Training in Bangalore

    ReplyDelete
  10. Nice! Very useful information. Munafa Wala Loan agency in Jaipur provide loan at low interest rate HDFC Personal Loan in Jaipur

    ReplyDelete