cancel
Showing results for 
Search instead for 
Did you mean: 

Primary keu & UNique Key

Former Member
0 Kudos

Hi all,

Is there any difference between primary key and unique key.

thanks

Aashish

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

The Main difference is that Unique Key allows null value but Primary Key doesn't allow null values.

thats it.

former_member188685
Active Contributor
0 Kudos

Primary key and Unique Key Both are same

regards

vijay

Former Member
0 Kudos

aashish,

As you can see, all of the developers on this thread have DB installations that do not permit non-unique primary keys.

Please check with your DBAs to see if yours does... as unique and primary keys are NOT truly the same. Oracle, for example, will permit non-unique primary keys. It is NOT the "suggested" model... but it is possible.

Please reward points accordingly and close the thread.

Former Member
0 Kudos

Hi,

Pls award points to useful answers.

Regards,

Amit M.

abdul_hakim
Active Contributor
0 Kudos

Hi,

Primary is used to uniquely identify the records in the table.Primary key is a Unique key by default.

<b>If there is a primary key then there is a unique key.

If there is a unique key then there is a primary key.</b>

Thanks,

Abdul

Former Member
0 Kudos

Hi aaahish,

1. This concept of primary key and unique key

comes into picture at the database level

(especially oracle)

2. The only difference is that

unique key allows

insertion of a NULL value

into the key field(s)

Where as primary key does not allow.

3. Similary is ;

Both maintain unique/distinct values

in the table.

I hope it helps.

regards,

amit m.

Former Member
0 Kudos

Hi aashish,

<b>Primary key</b>

Both are same.<b>A primary key is usually called as an unique key</b>.A primary key is defined for each database table. A user-defined primary key can consist of one or more columns.<i>The primary key must have a unique value for each table row.</i> The primary key is either defined by the database user, or generated internally.

<b>

Foreign key</b>

If the values in a column (or a combination of columns) of a table always match the values of the primary key column of another table, then this column (or combination of columns) is called a foreign key.

Hope this helps u,

Regards,

Nagarajan.

Former Member
0 Kudos

A primary key is the "key" used to store a record in a database. Depending on how your DB is set-up, it can or can not be unique. It SHOULD BE, but it is not a requirement in all DBs.

A unique key is TRULY a unique (meaning no other records in the table will have the same key field values).

Reward points accordingly.

Former Member
0 Kudos

Bear in mind that this statement is not true on all DB installations - "The primary key must have a unique value for each table row."

Check with your DBAs to verify of your DB installation permits non-uniue primary keys. Again, it is NOT a good practice to do this... but some DB systems will permit it and some customers ACTUALLY use that functionality. I would NOT... but some do.