0

I know this gets asked a lot, but in my case, I feel like it shouldn't be an issue. My table has 2 foreign keys that allow for nulls, so I should be able to leave them blank, right?

My insert statement:

INSERT INTO Child (ChildID, FirstName, MiddleName, LastName, Gender, DOB)
VALUES (@ChildID, @FirstName, @MiddleName, @LastName, @Gender, @DOB)

I was hoping it would just leave the final 2 columns blank, for them to be filled out later, but all it does is give me an error.

The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Child__ChildGuar__2B3F6F97". The conflict occurred in database "ChildCare", table "dbo.ChildGuardian", column 'ChildGuardianID'.

I can re-work the database a little, if necessary.

botmin
  • 333
  • 1
  • 2
  • 7
  • --> " The conflict occurred in database "ChildCare", table "dbo.ChildGuardian", column 'ChildGuardianID'" - Do you have a trigger firing perhaps? – Mitch Wheat Nov 24 '13 at 02:01
  • I don't even know what a trigger is. How can I check for something like that? – botmin Nov 24 '13 at 02:06

1 Answers1

0

Have you tried passing in NULL for those values? You shouldn't have to pass anything, but it may help with troubleshooting.

I'd also check that Child.ChildGuardianID isn't an identity, and that it doesn't have a default value.

Benjineer
  • 1,530
  • 18
  • 22
  • I gave it a default value before without thinking about that. Thank you! – botmin Nov 24 '13 at 02:19
  • To check for triggers as @mitch wheat suggested, take a look here: [link](http://stackoverflow.com/questions/3177594/unable-to-find-where-triggers-are-stored-in-sql-server-2008) Note that you'll probably need SSMS to check/alter any of this stuff. – Benjineer Nov 24 '13 at 02:23
  • Oops, posted too late. Great! Don't forget to mark as answered :) – Benjineer Nov 24 '13 at 02:23
  • Is there an official way of doing that? – botmin Nov 24 '13 at 02:37