1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Deferrable primary key/.

Discussion in 'SQL PL/SQL' started by Vicky, Oct 8, 2015.

  1. Vicky

    Vicky Forum Advisor

    Messages:
    261
    Likes Received:
    11
    Trophy Points:
    260
    Location:
    Chennai
    How to create primary key for an existing table which contains duplicate records.,

    Actually, i just want to create a PK
    i, which ignores existing duplicate records and
    ii,should restrict only the upcoming new duplicate entries ....
     
    Last edited: Oct 8, 2015
  2. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
  3. ocprep

    ocprep Forum Advisor

    Messages:
    277
    Likes Received:
    76
    Trophy Points:
    410
    Location:
    Orlando, Florida
    As Jagadekara says -- there is no way to make a primary key that has this behavior. It is impossible to make a UNIQUE index on a column that contains duplicates and this is required for a column to be a PK. The closest you could come to the behavior you are asking for would be to make a non-unique index on the column and create a trigger or application logic that prevented INSERT operations that contained a value that already exists in the table and UPDATE operations that changed the value of that column to match that of an existing row in the table.

    The better option, though would be to clean up the table.