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:

OWNERCONSTRAINT_NAMESTATUS
SYSTEMPK_TEST_IDENABLED