I would like to know the difference between UNIQUE
and PRIMARY KEY
in Oracle , where UNIQUE
defines values that can not be repeated, and PRIMARY KEY
in thesis does the same thing.
I would like to know the difference between UNIQUE
and PRIMARY KEY
in Oracle , where UNIQUE
defines values that can not be repeated, and PRIMARY KEY
in thesis does the same thing.
PRIMARY KEY
defines what the primary key of the table is. That is, what is the set of columns that should identify a tuple in a unique and unambiguous way. In addition, the table is usually organized internally according to how the primary key is defined. In addition, what is exported to other tables as a foreign key is the primary key.
However, there may be more than one way to uniquely identify a tuple, and that is where UNIQUE
enters.
For example, let's assume that a usuario
table has the following fields: name, id, CPF, RG, email, and date of birth.
Let's see, id would be the primary key. However, we can not have two users with the same email, so the email is UNIQUE
. Also we can not have two users with the same RG or the same CPF, which are UNIQUE
as well.
In addition, from time to time a person can change RG. If the RG was the primary key, you would have to come out cascading the changes on all the foreign keys, a problem that does not exist in columns UNIQUE
that are not PRIMARY KEY
.
Another difference is that UNIQUE
columns can be NULL
, whereas PRIMARY KEY
columns can not. For example, in that case I gave up, this would be useful if you are to register a foreigner who does not have a CPF and RG. If one of these was a primary key, you would get screwed.
As the SOEN
The primary key:
The unique key:
There may be more than one in a table
You can get NULL values
In addition, the use of primary and foreign guarantors ensure compliance and integrity of the data and the structure of tables EX: You can not delete a table or a data that is dependent on another, which prevents any nonconformity.
Primary Key
:
Primary Key
is a unique identifier of a record in a table Unique Key
:
Unike Key
in a table Primary Key
Unique Key
can be null and, in the case of null, not unique to the registry source: link