Create Primary Key Using Alter Table Statement in Oracle

In my current company, besides SQL Server we also use Oracle. In terms of features and syntax, there is no significant difference between these two DBMS. For example, when we want to add primary key to existing database, we can use this Oracle PL/SQL command:

ALTER TABLE table_name 
ADD CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ..., column_n);

As a side note, you cannot run this command if your existing data still contain duplication on the primary key. Thus, you must remove them first.

Leave a comment