Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 554
Thorsten Niehues Avatar asked Jun 11 '15 10:06

Thorsten Niehues


People also ask

Can I add primary key to existing table?

Because a table can have only one primary key, you cannot add a primary key to a table that already has a primary key defined. To change the primary key of a table, delete the existing key using a DROP clause in an ALTER TABLE statement and add the new primary key.

How do I add a primary key to a column in a table?

Now, to create a PRIMARY KEY constraint on any column when the table already exists (NO EARLIER PRIMARY KEY DEFINED), use the following SQL Syntax: ALTER TABLE [Table_Name] ADD PRIMARY KEY (ID);

How do I add a primary key without dropping the table?

How do I add a primary key without dropping the table? However, you can only use the ALTER TABLE statement to create a primary key on column(s) that are already defined as NOT NULL. If the column(s) allow NULL values, you will not be able to add the primary key without dropping and recreating the table.


1 Answers

ALTER TABLE schema.table ADD PRIMARY KEY (column1,column2)
like image 90
Thorsten Niehues Avatar answered Sep 21 '22 06:09

Thorsten Niehues