Add primary key

To add primary key on a table of Oracle database you must use the alter table command.

Syntax

ALTER TABLE table_name
ADD CONSTRAINT constraint_name
PRIMARY KEY(col_name);

Add primary key example

  
ALTER TABLE test 
ADD CONSTRAINT pk_test_id 
PRIMARY KEY(id);

Output:

table TEST altered.

Check constraints

SELECT OWNER, CONSTRAINT_NAME, STATUS
FROM user_constraints
WHERE table_name = 'TEST';

Output:

OWNER CONSTRAINT_NAME STATUS
SYSTEM PK_TEST_ID ENABLED