DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Difference between Primary Key and Unique Constraints

  1. #1
    Join Date
    Mar 2001
    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.


  2. #2
    Join Date
    Mar 2001
    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.


  3. #3
    Join Date
    Feb 2001
    I am giving you an example.

    Table Employee has following columns

    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

Click Here to Expand Forum to Full Width