Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on difference between unique key and primary key within the SQL forums, part of the Databases category; need answer...
|
|||||||
|
|||
|
Re: difference between unique key and primary key
unique key enforces only uniqueness--ie--no duplicate value
primary key enforces both uniqueness and not null an index is also created on primary key field. |
|
|||
|
Re: difference between unique key and primary key
A unique key must uniquely identify all possible rows that exist in a table and not only the currently existing rows. Examples of unique keys are Social Security numbers (associated with a specific person[1]) or ISBNs (associated with a specific book). Telephone books and dictionaries cannot use names or words or Dewey Decimal system numbers as candidate keys because they do not uniquely identify telephone numbers or words.
A primary key is a special case of unique keys. The major difference is that for unique keys the implicit NOT NULL constraint is not automatically enforced, while for primary keys it is. Thus, the values in a unique key columns may or may not be NULL. Another difference is that primary keys must be defined using another syntax. For more information refer to the following link Unique key - Wikipedia, the free encyclopedia Thanks Sushma |
| The Following User Says Thank You to Sushma Mosali For This Useful Post: | ||
|
|||
|
Quote:
|
|
|||
|
Re: difference between unique key and primary key
hai,
The column holding the primary key constraint cannot accept null values.whereas column holding the unique constraint can accept null values assume that t3 is a table with two columns t1 having primary key constraint and t2 having unique constraint if u try to insert null into t2 it will accept that values whereas column t1 will not accept null Regards, Nithya.R |
| The Following User Says Thank You to nithui For This Useful Post: | ||
|
|||
|
Re: difference between unique key and primary key
In a table there can be multiple unique keys but there can be only one primary key.
Unique key can be defined as null but primary key cann't be set to null. |
|
|||
|
Re: difference between unique key and primary key
Unique key--The data in the column is unique. i.e if you specify NULL that should be only one NULL value
Primary key--No NULL at all |
| The Following User Says Thank You to venugec For This Useful Post: | ||
|
|||
|
Re: difference between unique key and primary key
both are using uniquely identify a row
but a table can have more than 1 unique keys.a tabe can have only one primary key and unique key allows NULL values but primary key never allows NULL values |
|
|||
|
Re: difference between unique key and primary key
primary key--> primary key is uniqe column in particular table and null value is not allow or other words duplicate value not allow as well as null value is not accepted.. in one table have only one primary key it called primary key
unique key--> unique key is same as primary key but in unique key allow null value |
|
|||
|
Re: difference between unique key and primary key
difference between unique and primary key is
unique identifies only unique values(including null values ) primary key identifies only unique(but not null values) |
|
|||
|
Re: difference between unique key and primary key
unique should contain the null value but primary key cannot take a null value
|
|
|||
|
Re: difference between unique key and primary key
1. Primary Key doesn't allow a null value but Unique key can have at most one null value.
2. Only one Primary key can be declared in a table but there can be multiple unique keys in a table. |
|
|||
|
Re: difference between unique key and primary key
unique key can have more than one null value! primary key cannot have null values at all... both can be referenced by foreign keys...but u can hav only 1 primary key but any number of unique keys...
|
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| difference bet unique and distinct | smitai | Oracle Certification | 4 | 4 Weeks Ago 08:35 AM |
| Initializing Primary Key | PRINCEJOHNWESLEY | MY SQL | 0 | 09-10-2008 09:57 AM |
| difference between unique and distinct | arpitace | Oracle | 2 | 08-12-2008 08:17 AM |
| Primary Key References | krishnaindia2007 | Oracle | 1 | 03-06-2008 07:38 AM |
| what is the difference between Primary Key and Index Key ? | skravipati | SQL | 1 | 09-07-2007 01:46 AM |