Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 NULL in foreign key
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

152 Posts

Posted - 11/19/2013 :  08:04:34  Show Profile  Send desikankannan a Yahoo! Message  Reply with Quote
I want to insert NULL value in foreign key reference, my field name is
fid i try to insert NULL value to this field did = '' below find my query

UPDATE DeathData SET FirstName = 'Jack', MiddleName = '', LastName = 'Brown', Title = '', BirthDate = '2/1/1933', DeathDate = '7/30/2008', VisitationLocation = 'Mowery Funeral Service', VisitationDate = '8/1/2008', VisitationTime = '1:00 p.m.-8:00 p.m. ', FuneralDate = '8/2/2008', FuneralTime = '10:00 a.m.', ObitText = 'Public', ObitPhoto = 'obitphotos/brownjack.jpg', BurialTime = '', FuneralType = 'Public', BurialType = 'Public', Note = '', DisplayOnWebsite = 'Y', fid = '46', bid = '294', did = '' WHERE ID = 29

error message

Msg 547, Level 16, State 0, Line 1
The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Donations". The conflict occurred in database "Moweryfinal", table "dbo.tbldonations", column 'did'.
The statement has been terminated.


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 11/19/2013 :  08:14:57  Show Profile  Reply with Quote
You need to have a row with the value of '' in the did column of the referring dbo.tbldonations table.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/19/2013 :  09:09:12  Show Profile  Reply with Quote
'' is not same as NULL
'' means blank value
whereas NULL means unknown value. Its not stored internally as a value in SQL Server. It just represents condition unknown value
to set it to NULL you need to explicitly pass it as

did = NULL and not
did = ''

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000