How to add a (primary) key to an existing table using SAP HANA

36.5k views Asked by At

What is the SQL command to add a (primary) key to a table in SAP HANA?

The ALTER TABLE docu form SAP Library is cryptic to me

3

There are 3 answers

1
Thorsten Niehues On
ALTER TABLE schema.table ADD PRIMARY KEY (column1,column2)
0
KABIL ARASAN On

To add constraints to a column:

alter table "Schema_Name"."Table_Name"  add primary key ("Column_Name");
0
Manish Gupta On

For creating Primary key on existing table use the following syntax in SQL Console:

alter table "schemaName"."tableName" add constraint primary_key_alias Primary KEY("Column_Name");

Here primary_key_alias is the name for the primary key. For more info goto: SAP help