SQL Server - Alter Primary Key of Table with existing foreign key

Asked By Versha on 14-Nov-12 06:32 AM
hi,
        Table1                                                        Table2
                     shopid  (PK)                                                              Shopid (PK,FK to Table1)
                     Lineid   (FK to Table3)                                                Terminalid (PK)

Need to Add Lineid as PK 
     
        Table1                                                           Table2
                     shopid  (PK)                                                   Shopid (PK,FK)
                     Lineid   (PK,FK)                                               Terminalid (PK)


  ForeignKey Constraint is removed of Table1
  ForeignKey Constraint is removed of Table2
  Primary Key Constraint is removed of Table1
  
  Primary Key Constraint is added to Table1
  ForeignKey   Constraint is added to  Table1

Throws Error while Adding 
ForeignKey Constraint to  Table2

Error:
The columns in table  do not match an existing primary key or UNIQUE constraint.




Robbe Morris replied to Versha on 14-Nov-12 09:55 AM
Do a query to see which rows violate the constraint and fix the rows.