Alex Rivera | Logout

Does making a primary key in multiple columns generate indexes for all of them?

Asked 2009-02-10T12:04:21.953
9

If I set a primary key in multiple columns in Oracle, do I also need to create the indexes if I need them?

I believe that when you set a primary key on one column, you have it indexed by it; is it the same with multiple column PKs?

Thanks

Edit
Report

2 Answers

2

You will get one index across multiple columns, which is not the same as having an index on each column.

answered 2009-02-10T12:09:47.323
0

You may need to set individual indexes on the columns depending on your primary key structure.

Composite primary keys and indexes will create indexes in the following manner. Say i have columns A, B, C and i a create the primary key on (A, B, C). This will result in the indexes

  • (A, B, C)
  • (A, B)
  • (A)

Oracle actually creates an index on any of the left most column groupings. So... If you want an index on just the column B you will have to create one for it as well as the primary key.

P.S. I know MySQL exibits this left most behaviour and i think SQL Server is also left most

answered 2009-02-10T23:02:36.350

Your Answer