Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Getting Foreign Key Constraint Error Unusually

Getting Foreign Key Constraint Error Unusually

Scheduled Pinned Locked Moved Database
databasedebugginghelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    Hi All, I have a stored procedure that is inserting some values in Master and details table and I am getting the following error. Some times I am getting this error but some times I am not getting this error. When I am inserting detail table values I am checking everything if I am inserting any values that are not there in the Master table, but I am not getting any sign that I am inserting any values that are not there in Master table.

    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Identifier_Entity". The conflict occurred in database "IdentityResolutionService", table "dbo.Entity", column 'EntityId'.

    My scenario is: I have Entity table, Identifier table, Entity is the master table Identifier is the detail table. I am actually taking data from another table called Students to load all the students of a state, sid, dsid and ssn are the columns that are important from the students table. One sid may have multiple dsids depending upon year, school district etc, one ssn one sid. Now I have taken Rank on the SID to load all this data from Students table to Staging table. Now I have taken all the distinct SIDs and put it into Master table. In the Identifier table when I am loading the SIDs, DSIDs and SSNs, I have taken the corresponding Rank value for that row, instead of creating one. I explained this only because there is no way that I can miss the Foreign key relationship. But one thing when I am loading the Entity values I am making it as Auto increment off, insert statement and then making it on because there is another application that is using the same table as auto increment on. But another thing is as the user doesn't have alter table permissions, I have created a Stored Proc which takes table name and insert statement as parameters so that I can make auto increment off and run the insert command in the parameter and makes auto increment on. After doing this I make auto increment on. This stored procedure runs under proxy user account. Then I run insert into Identifier table, some how the insert into Identifier table is failing with the above error message. What could be the reason. Some time it works, some time doesnt. Is it because of dynamic sql or proxy user or the huge amount of data that is being processed because of all the students in a state, like around 4 or 5 million records am processing. In the Identifier table it is having more than 10 million records or am I doing any mistake. Because of its hugeness I am unable to debug the Stored Proc also very well the re

    M J 2 Replies Last reply
    0
    • I indian143

      Hi All, I have a stored procedure that is inserting some values in Master and details table and I am getting the following error. Some times I am getting this error but some times I am not getting this error. When I am inserting detail table values I am checking everything if I am inserting any values that are not there in the Master table, but I am not getting any sign that I am inserting any values that are not there in Master table.

      The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Identifier_Entity". The conflict occurred in database "IdentityResolutionService", table "dbo.Entity", column 'EntityId'.

      My scenario is: I have Entity table, Identifier table, Entity is the master table Identifier is the detail table. I am actually taking data from another table called Students to load all the students of a state, sid, dsid and ssn are the columns that are important from the students table. One sid may have multiple dsids depending upon year, school district etc, one ssn one sid. Now I have taken Rank on the SID to load all this data from Students table to Staging table. Now I have taken all the distinct SIDs and put it into Master table. In the Identifier table when I am loading the SIDs, DSIDs and SSNs, I have taken the corresponding Rank value for that row, instead of creating one. I explained this only because there is no way that I can miss the Foreign key relationship. But one thing when I am loading the Entity values I am making it as Auto increment off, insert statement and then making it on because there is another application that is using the same table as auto increment on. But another thing is as the user doesn't have alter table permissions, I have created a Stored Proc which takes table name and insert statement as parameters so that I can make auto increment off and run the insert command in the parameter and makes auto increment on. After doing this I make auto increment on. This stored procedure runs under proxy user account. Then I run insert into Identifier table, some how the insert into Identifier table is failing with the above error message. What could be the reason. Some time it works, some time doesnt. Is it because of dynamic sql or proxy user or the huge amount of data that is being processed because of all the students in a state, like around 4 or 5 million records am processing. In the Identifier table it is having more than 10 million records or am I doing any mistake. Because of its hugeness I am unable to debug the Stored Proc also very well the re

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      indian143 wrote:

      I am loading the Entity values I am making it as Auto increment off,

      I suspect this is the cause of the problem, I can't see any reason for removing the IDENTITY attribute and the error message points directly to this as issue.

      Never underestimate the power of human stupidity RAH

      I 1 Reply Last reply
      0
      • I indian143

        Hi All, I have a stored procedure that is inserting some values in Master and details table and I am getting the following error. Some times I am getting this error but some times I am not getting this error. When I am inserting detail table values I am checking everything if I am inserting any values that are not there in the Master table, but I am not getting any sign that I am inserting any values that are not there in Master table.

        The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Identifier_Entity". The conflict occurred in database "IdentityResolutionService", table "dbo.Entity", column 'EntityId'.

        My scenario is: I have Entity table, Identifier table, Entity is the master table Identifier is the detail table. I am actually taking data from another table called Students to load all the students of a state, sid, dsid and ssn are the columns that are important from the students table. One sid may have multiple dsids depending upon year, school district etc, one ssn one sid. Now I have taken Rank on the SID to load all this data from Students table to Staging table. Now I have taken all the distinct SIDs and put it into Master table. In the Identifier table when I am loading the SIDs, DSIDs and SSNs, I have taken the corresponding Rank value for that row, instead of creating one. I explained this only because there is no way that I can miss the Foreign key relationship. But one thing when I am loading the Entity values I am making it as Auto increment off, insert statement and then making it on because there is another application that is using the same table as auto increment on. But another thing is as the user doesn't have alter table permissions, I have created a Stored Proc which takes table name and insert statement as parameters so that I can make auto increment off and run the insert command in the parameter and makes auto increment on. After doing this I make auto increment on. This stored procedure runs under proxy user account. Then I run insert into Identifier table, some how the insert into Identifier table is failing with the above error message. What could be the reason. Some time it works, some time doesnt. Is it because of dynamic sql or proxy user or the huge amount of data that is being processed because of all the students in a state, like around 4 or 5 million records am processing. In the Identifier table it is having more than 10 million records or am I doing any mistake. Because of its hugeness I am unable to debug the Stored Proc also very well the re

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        indian143 wrote:

        I explained this only because there is no way that I can miss the Foreign key relationship

        But the error is telling you SPECIFICALLY that that assumption is wrong. Hypothetically how do you know that, for instance, the SSN was never entered wrong? Or that someone didn't make up a SSN? The error is telling you that either you must clean the existing data before using it or you must use another key.

        I 1 Reply Last reply
        0
        • J jschell

          indian143 wrote:

          I explained this only because there is no way that I can miss the Foreign key relationship

          But the error is telling you SPECIFICALLY that that assumption is wrong. Hypothetically how do you know that, for instance, the SSN was never entered wrong? Or that someone didn't make up a SSN? The error is telling you that either you must clean the existing data before using it or you must use another key.

          I Offline
          I Offline
          indian143
          wrote on last edited by
          #4

          I am not using SSN directly as foreign key what I am using is the rank generated depending upon the SID is foreign key means for each SID there will be an EntityId and the same Entity Id I will be using for loading the DSID and SSN too. There is no way that I will go beyond Entities that are created by SID's Rank. I can give you the code, can you please look into it.

          Thanks & Regards, Abdul Aleem Mohammad St Louis MO - USA

          1 Reply Last reply
          0
          • M Mycroft Holmes

            indian143 wrote:

            I am loading the Entity values I am making it as Auto increment off,

            I suspect this is the cause of the problem, I can't see any reason for removing the IDENTITY attribute and the error message points directly to this as issue.

            Never underestimate the power of human stupidity RAH

            I Offline
            I Offline
            indian143
            wrote on last edited by
            #5

            Can I put my code here

            Thanks & Regards, Abdul Aleem Mohammad St Louis MO - USA

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups