Saturday , November 23 2024

Primary Key In Oracle

In today’s article, we will be explaining the concept of a primary key in Oracle, which is a single field or combination of fields that uniquely defines a record.

It does not allow empty values ​​to be entered in the relevant column and ensures that the entered value is unique.

Therefore, Primary Key is the combination of UNIQUE constraint and NOT NULL constraint.

While defining constraints, they can be named by the user or created without specifying a name.

In this case, Oracle gives the constraint a name starting with SYS_.

Since we did not give a name to the Primary Key, its name started with SYS_.

If a name is given to the Primary Key and it is queried, the name we gave will be returned.

When the Primary Key constraint is created, Oracle also creates a unique index with the same name.

The created index can be created in the default tablespace of the user performing the operation, or in the tablespace we specify.

Since the default Tablespace is SYSTEM, it was created here.

When I specify USERS, it is created there.

There can be only one Primary Key constraint on a table. An error is received when a second one is created.

ERROR at line 1: 

ORA-02260: table can have only one primary key

A Primary Key constraint can be created on more than one column.

Loading

About Onur ARDAHANLI

Leave a Reply

Your email address will not be published. Required fields are marked *