Unable To Create Relationship Error - Why ??

  • ALTER TABLE [dbo].[Enrollment] ADD

     CONSTRAINT [ClassStudentMap2Enrollment] FOREIGN KEY

     (

      [CSMid]

    &nbsp REFERENCES [dbo].[ClassStudentMap] (

      [CSMid]

    &nbsp ON DELETE CASCADE

    GO

    Server: Msg 547, Level 16, State 1, Line 1

    ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'ClassStudentMap2Enrollment'. The conflict occurred in database 'Schoolwise', table 'ClassStudentMap', column 'CSMid'.

    What's going on here? My brain is on strike. I dropped this table, created it again using a SELECT INTO from tmp_Enrollment and tried to recreate the constraints, indexes etc from a backup script of Enrollment. Everything went well apart from the above code.

    Thanks.

  • Have you checked for invalid data that may make the foreign key fail (maybe some data has been deleted in the parent table in between data transfers)?

  • You little beauty - that was it - my brain was on strike

    Thanks for the speedy reply - very much appreciated indeed.

     

    Regards.

  • I wouldn't go as far as say little, but I'll take the beauty part of the compliment .

    HTH.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply