I have seen couple of sample tables one is with UNIQUE INDEX and other is with UNIQUE KEY. what is the difference between two?? or both are same?
A primary key is a column, or a combination of columns, that can uniquely identify a row. It is a special case of unique key. A table can have at most one primary key, but more than one unique key. When you specify a unique key on a column, no two distinct rows in a table can have the same value.
Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint. However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.
Unique indexes are indexes that help maintain data integrity by ensuring that no rows of data in a table have identical key values. When you create a unique index for an existing table with data, values in the columns or expressions that comprise the index key are checked for uniqueness.
Yes, absolutely. A unique constraint creates a unique index.
CREATE TABLE
KEY is normally a synonym for INDEX.
You can use them interchangeably as described in syntax page
[CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With