Skip to Content
Oct 17, 2019 at 06:37 PM

how to add a primary key in SAP Hana Studio

2248 Views Last edit Jul 08, 2020 at 01:56 AM 2 rev


I created a table and at the time there was no primary key(s). Now, I need to define a primary key to an existing column. The SQL is, as follows:

ALTER TABLE "RAP"."My table" ADD constraint PRIMARY KEY "Brand";

The error message is: SAP DBTech JDBC: [257]: sql syntax error: incorrect syntax near "KEY": line 1 col 71 (at pos 71).

Any help will be greatly appreciated.

The help for this command goes like this:

<add_constraint_clause> ::= 
 ADD [CONSTRAINT <constraint_name>] <table_constraint>

<constraint_name> ::= <identifier>
<table_constraint> ::= 
<unique_constraint_definition> ::= 
<unique_specification> (<unique_column_name_list>)