-
What is the difference between a primary key and unique constraints? Please refer to the following example:
Customer Table
Customer ID varchar PK
Customer Name varchar
Customer Address varchar
Customer Country Code varchar
Customer Area Code varchar
Suppose I create a unique constraint (Customer Country Code+Customer Area Code), does it make any difference to use this constraint instead of the primary key.
Apprecieate your advise.
Thanks
-
On a primary key column, both NOT NULL and UNIQUE constraints will
enabled. Where as if there is only UNIQUE constraint on a column,
NULL values could be inserted.
In the queries, if searched for NULL columns with UNIQUE constraint,
the optimizer does a full table scan.
However, null values cannot be inserted into the primary key columns.
Choosing between primary key and unique constraint depend on
the application/design requirement. If the column could take null values
then it cannot be primary key.
hptse
-
I am giving you an example.
Table Employee has following columns
empcode,
ESIno,
..
..
in above said table, both fields are individualy
ok for Uniq Key, but only EmpCode can be
primary key, because ESI no. may
be null for some employees. But whenever it will be updated
it must be uniq value.
PF no. is also example for Uniq Key.
P. Soni
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|