Making an index unique that is technically not unique
I have a 'Messages' table that has the following (relevant to this question) fields:
SenderID | int
DateSent | DateTime
I was wondering about creating a unique index on those two fields and have a question. Technically, this combination of fields isn't a unique combination (ie by design there's nothing stopping it), however practically it will be. The application that is using this table is a web app and so a sender will never actually be able to send messages immediately after one anoth开发者_C百科er due to page refresh time, etc.
Is it acceptable to make this index a unique one?
UNIQUE
is an index and constraint at the same time. If it has to be unique, than make it unique. If you want just to improve query performance, you can create a non-unique index on 2 fields.
If you make it unique, and your app runs fast enough, you will get a key violation.
I would not make it unique.
What the purpose of making this index unique? I guess including DateSent in the index doesn't reduce your queries time.
精彩评论