If I have a table with the following columns as the primary key: Username, Title, Start Date, then the database will automatically create an index on it.
- If I want to select by username, and start date for a query…..will it use the index above OR do I need to specify an additional index?
- If title and start date identify uniquely but I also add username to the primary key, would that make it a superkey?
You have a complex condition, say, like this:
If your table’s PK defined like:
Then index will be used for first part involving username field. startdate values will be evaluated in natural order.
If you want index to be used for both parts of complex condition, either create additional index on startdate or change order of fields in the PK:
It is a good practice not to abuse an unique index with additional fields. In your case create PK on title and start date and then (if necessarily) create separate index on user name field.