Results 1 to 6 of 6


  1. #1

    Thumbs up What's the difference between a primary key and a unique key?

    Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a non-clustered index by default. Another major difference is that, primary key does not allow NULLs, but unique key allows one NULL only.

  2. #2

    Default

    Primary Key:

    • Can be only one in a table
    • In some DBMS it cannot be NULL - e.g. MySQL adds NOT NULL
    • Primary Key is a unique key identifier of the record


    Unique Key:

    • Can be more than one unique key in one table
    • Unique key can have null values
    • It can be a candidate key
    • Unique key can be null and may not be unique

  3. #3

    Default

    Primary Key is used to identify a row (record) in a table, whereas Unique-key is to prevent duplicate values in a column (with the exception of a null entry). By default SQL-engine creates Clustered Index on primary-key if not exists and Non-Clustered Index on Unique-key

  4. #4

    Default

    rimary Key is used to identify a row (record) in a table, whereas Unique-key is to prevent duplicate values in a column (with the exception of a null entry).

  5. #5

    Default

    Primary key is an index that helps locate table rows easily, however, primary key is also unique. but a table can only have one primary key which is incremental by default. unique key is just as it sounds, it must be unique, no duplication of data. example is making the email column of your database unique. you can have more unique keys in your table.

  6. #6

    Default

    Both PRIMARY KEY and UNIQUE KEY enforces the Uniqueness of the values (i.e. avoids duplicate values) on the column[s] on which it is defined. These are the some difference between Primary and unique key:


    PRIMARY KEY:


    It doesn’t allow Null values.
    By default it adds a clustered index
    A table can have only one PRIMARY KEY Column[s]




    UNIQUE KEY


    Allows Null value. But only one Null
    By default it adds a UNIQUE non-clustered index
    A table can have more than one UNIQUE Key Column[s]


Similar Threads

  1. What is a primary key?
    By kunal in forum Databases
    Replies: 61
    Last Post: 10-20-2018, 06:01 AM
  2. What's the difference between new users and unique users in analytics?
    By Donald in forum Internet Marketing, SEO, PPC, Web Development Forums
    Replies: 3
    Last Post: 01-24-2017, 06:22 AM
  3. Replies: 6
    Last Post: 12-16-2016, 04:34 AM
  4. Replies: 9
    Last Post: 01-22-2016, 05:01 AM
  5. Primary Key - Unique Identifier
    By edwrdwlsn in forum Computer Forum
    Replies: 0
    Last Post: 04-14-2013, 13:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
| UKC | VPS Germany | Webmaster Marketplace | Web Hosting Forum | Domain Name Forum | VPS Forum | Webmaster Forum | Website Design Forum | Sites For Sale |