Answered Questions

  • what is the difference between primary key, unique key, surrogate key?

    Star Read Best Answer

    Editorial / Best Answer

    Kolta Sam  

    • Member Since Jul-2011 | Jul 10th, 2011


    Primary Key:

    It is a visible key
    It generated by user or application.
    It could be changed by the user or application.
    It could be queried
    It used to form a relation between tables
    It shouldn’t contain null value
    It resemble table row
    It is a unique identifier for a table object.
    It contains only one key
    It could contain numeric and strings characters.
    It is an unique key which each row contain a distinct different key.
    Example for it is a customer_Id.
    It always starts by number one and second is two and so on but can starts with a different number.
    Could created on one or more columns
    No duplicate records

    Secondary Key:

    It used to form a relation between tables.
    It is alternate table key.
    It used to search data with primary key
    It could contains null value
    It could contains more than one secondary key for each table
    Created only on one columns
    No duplicate records
    It creates index clustered by default


    Surrogate Key:

    It is invisible key for the user or the application.
    It resembles database entity.
    It generated by the system so it is invisible for user and application.
    It shouldn’t contain null values
    Only one surrogate key for each data entity
    Its value is unique system wide.
    Its value is never manipulated by the user or the application.
    It never reused
    It is frequently sequential number
    It called synthetic key, an entity identifier, a system-generated key, a database sequence number, a factless key, a technical key, or an arbitrary unique identifier
    No duplicate records

    gopi

    • May 18th, 2018

    Primary key not allow null values where as unique allows but both are alternates.
    surrogate key serve as primery key in type 2 dimension tables

    Sukdya

    • Nov 27th, 2017

    Primary key doest not allow null values but unique key allows only one null value.