Both Primary & Unique keys are Indexes.
Index - An index is a structure in a table that orders the data. It allows the database to access data quickly (In MySQL its implemented using B-tree algorithms).
Primary Key - This is an index that cannot be NULL, Primary Keys are used in building relationships between tables in a database. (an index is automatically created on the primary key). The difference between primary and ordinary keys is that there can be multiple keys, but only one primary key.
Unique Key - Unique and Index are same, the difference is, in Unique, duplicate are not allowed in any circumstances and that is enforced by database server. Primary key(s) qualify to be Unique on basis of their uniqueness.
In case, your table has 2 primary keys means that the 2 fields together form one unique key. Each field by itself may have repeating values, but both primary keys combined together must be unique.
Blog on things around me - Applications, Java Platform, Free & Open Source Software, Gadgets, Utilities...
Subscribe to:
Post Comments (Atom)
Total Pageviews
Diving into the Controversial World of IPL with Lalit Modi
Lalit Modi, the mastermind behind the Indian Premier League (IPL), recently had a candid interview with Raj Shamani. The interview delved d...
-
Bugzilla is the Bugs/Issues Tracking Tool from The Mozilla Organization. Version 2.18 is the latest stable release. There are couple of res...
-
Two MIT math graduates bump into each other at Fairway on the upper west side. They hadn't seen each other in over 20 years. The first g...
3 comments:
Nicely explained, I guess the same would stand out for DB2 as well...
Refer following
href="http://mainframewizard.com/content/difference-between-primary-key-and-unique-key">Difference between primary and unique key
That's add value to original post. worth including in my list of differences between primary and unique key.
I have look for this explanation all around the Internet.
However not new to me, more than 30 years ago using relational database tables, let me tell to whom reads this.
Primary Key and Unique Keys in the context of the table are equal. Primary keys were created for relational tables, where you relate one table with the other without the need to link fields on each table.
Post a Comment