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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 NULL in foreign key

Author  Topic 

desikankannan
Posting Yak Master

152 Posts

Posted - 2013-11-19 : 08:04:34
Hi,
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.

Desikankannan

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-11-19 : 08:14:57
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-19 : 09:09:12
'' 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -