Results 1 to 4 of 4
  1. #1
    Join Date
    May 2002
    Location
    Cape Town , South Africa
    Posts
    30

    Unanswered: Missing Primary Keys

    HI Folks ,

    I have a problem with the primary keys in my main Db , I want to setup replication and looks like someone tampered with my database by removing the primary keys.and in order to setup replication i need this table to have primary keys .THere are duplicates in that table but they are nessecary...and for this reason the primary keys do not want to "stick" when i try and specify them.Can anybody help

    Burner

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Without the PK, transactional replication won't work. You could use snapshot replication if you wanted.

    If your table needs to have duplicate primary keys, you have a design problem. At some point, you'll probably need to fix it.

    -PatP

  3. #3
    Join Date
    May 2002
    Location
    Cape Town , South Africa
    Posts
    30

    missing primary keys

    Hi pat ,

    I know taht it wont work. What I want to know is ; is there a way to "restore" the primary keys ?What i did now was create another table with the exact same design ..specified my primary keys..but what i want to do now is import all my data into this table including my duplicates ..is there a way to do this ...using a script or something ..cause dts will not allow duplicates to be importing because of the primary key set on the table .

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'm confused. I think that you wnat ALTER TABLE ADD CONSTRAINT if you want to put the PK constraint back on the table.

    If you are trying to clean out the table, you can use:
    Code:
    SELECT *
       FROM icky_table AS a
       WHERE  1 < (SELECT Count(*)
          FROM icky_table AS b
          WHERE  b.PK = a.PK)
    This will show you the duplicate rows based on the PK values. You'll have to sort out which of those rows you want to keep and which you want to discard.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •