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
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.
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? 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.
ALTER TABLE schema.table ADD PRIMARY KEY (column1,column2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With