on 12-19-2005 2:03 PM
Hi all,
Is there any difference between primary key and unique key.
thanks
Aashish
The Main difference is that Unique Key allows null value but Primary Key doesn't allow null values.
thats it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Primary key and Unique Key Both are same
regards
vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Hi,
Pls award points to useful answers.
Regards,
Amit M.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.