Reference:Oracle documentation “Oracle Database enforces all PRIMARY KEY constraints using indexes”
Q’s
1> I did not understand the reason behind having a constraint and a key(that would also implement the constraint i.e. in this case PRIMARY KEY constraint and PRIMARY KEY index)?
2> Should I implement a key or a constraint when building database tables?
3> Are there any scenarios where using one over the other would be a +ve/-ve factor?
I’m not sure that I understand the question.
In Oracle, when you declare a primary key constraint, Oracle will implicitly create an index to enforce that constraint if no suitable index already exists to enforce the constraint. It is not an “either/or” situation where you create one or the other– you’re always going to have both a primary key constraint and an index to enforce that constraint.
You do have a choice about whether to create the index separately prior to creating the constraint and telling Oracle to use the index to enforce the constraint or whether to allow Oracle to implicitly create the index. It generally doesn’t matter which approach you choose but there are things to be aware of.
An example that creates a non-unique composite index with a different name than the primary key constraint that is then used to enforce the primary key constraint.